-
Notifications
You must be signed in to change notification settings - Fork 4
/
scrape.js
55 lines (43 loc) · 1.42 KB
/
scrape.js
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
// 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;
let notes = ['', ''];
while (notes.length !== 0) {
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');
notes = getNotes(doc);
allNotes = allNotes.concat(notes);
i += 1;
}
return allNotes;
};
getAllNotes().then();