forked from Beasta/etherscan-note-scraper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscrape.js
More file actions
56 lines (43 loc) · 1.43 KB
/
scrape.js
File metadata and controls
56 lines (43 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// obtained from https://gist.github.com/Zerquix18/069c414f62e98a4333d1191a3aeb3f7f#file-getallnotes-js
// runs in the browser console at https://etherscan.io/mynotes_address?p=1
const getNotes = (document) => {
const figure = document.getElementById('SVGdataReport1');
if (! figure) {
throw new Error('Could not find SVGdataReport1')
}
const table = figure.firstElementChild;
const body = table.lastElementChild;
if (body.childNodes[1].childElementCount === 1) {
return [];
}
const list = [];
body.childNodes.forEach(element => {
if (element.nodeName !== 'TR') {
return;
}
const nameTag = element.childNodes[2].textContent;
const address = element.childNodes[3].childNodes[0].textContent.trim();
const note = element.childNodes[3].childNodes[1].textContent.trim();
const dateCreated = element.childNodes[4].textContent;
list.push({ address, nameTag, note, dateCreated });
});
return list;
};
const getAllNotes = async () => {
let allNotes = [];
let i = 1;
while (true) {
const url = `https://etherscan.io/mynotes_address?p=${i}`;
const response = await fetch(url);
const result = await response.text();
const doc = new window.DOMParser().parseFromString(result, 'text/html');
const notes = getNotes(doc);
allNotes = allNotes.concat(notes);
if (notes.length === 0) {
break;
}
i++;
}
return allNotes;
};
getAllNotes().then(console.log)