-
Notifications
You must be signed in to change notification settings - Fork 0
/
scraper.js
92 lines (89 loc) · 4.54 KB
/
scraper.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// ! can scrape https://www.tgju.org/archive/price_dollar_rl or any other currencies' archive on this website
a = []
pages = document.querySelector("#DataTables_Table_0_paginate > span > a:nth-child(7)").innerText - 3
ii = 30 * (pages + 2) // one more than rows
jj = 30 * (pages + 2)
for (i = 0; i < ii; i++) {
for (j = 0; j < jj; j++) {
if (!a[i]) a[i] = []
}
}
v = 0
finished = false
delayedGreeting()
copy(a)
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function delayedGreeting() {
v = 0
b = 1
await sleep(3000);
for (b = 1; b <= pages; b++) {
if (b >= 5)
document.querySelector("#DataTables_Table_0_paginate > span > a:nth-child(5)").click()
else
document.querySelector("#DataTables_Table_0_paginate > span > a:nth-child(" + b + ")").click()
console.log("page num" + b)
z = 1
await sleep(3000);
for (; z <= 30; v++, z++) {
a[v][0] = document.querySelector("#table-list > tr:nth-child(" + z + ") > td:nth-child(1)").innerText
a[v][1] = document.querySelector("#table-list > tr:nth-child(" + z + ") > td:nth-child(2)").innerText
a[v][2] = document.querySelector("#table-list > tr:nth-child(" + z + ") > td:nth-child(3)").innerText
a[v][3] = document.querySelector("#table-list > tr:nth-child(" + z + ") > td:nth-child(4)").innerText
if (document.querySelector("#table-list > tr:nth-child(" + z + ") > td:nth-child(5) > span").className == 'high') {
a[v][4] = 1
a[v][5] = document.querySelector("#table-list > tr:nth-child(" + z + ") > td:nth-child(5)").innerText
a[v][6] = document.querySelector("#table-list > tr:nth-child(" + z + ") > td:nth-child(6)").innerText
} else {
if (document.querySelector("#table-list > tr:nth-child(" + z + ") > td:nth-child(5)").innerText != '-') {
a[v][4] = 0
a[v][5] = document.querySelector("#table-list > tr:nth-child(" + z + ") > td:nth-child(5)").innerText
a[v][6] = document.querySelector("#table-list > tr:nth-child(" + z + ") > td:nth-child(6)").innerText
} else {
a[v][4] = 2
a[v][5] = '-'
a[v][6] = '-'
}
}
a[v][7] = document.querySelector("#table-list > tr:nth-child(" + z + ") > td:nth-child(7)").innerText
console.log("page num " + b + " element num " + z + " filling array of " + v + " | " + a[v][0])
}
}
if (b > pages) {
lastpages()
}
}
async function lastpages() {
console.log("pashm runned")
await sleep(3000);
for (let b = 5; b < 7; b++) {
document.querySelector("#DataTables_Table_0_paginate > span > a:nth-child(" + b + ")").click()
z = 1
await sleep(3000);
for (; z <= 30; v++, z++) {
a[v][0] = document.querySelector("#table-list > tr:nth-child(" + z + ") > td:nth-child(1)").innerText
a[v][1] = document.querySelector("#table-list > tr:nth-child(" + z + ") > td:nth-child(2)").innerText
a[v][2] = document.querySelector("#table-list > tr:nth-child(" + z + ") > td:nth-child(3)").innerText
a[v][3] = document.querySelector("#table-list > tr:nth-child(" + z + ") > td:nth-child(4)").innerText
if (document.querySelector("#table-list > tr:nth-child(" + z + ") > td:nth-child(5) > span").className == 'high') {
a[v][4] = 1
a[v][5] = document.querySelector("#table-list > tr:nth-child(" + z + ") > td:nth-child(5)").innerText
a[v][6] = document.querySelector("#table-list > tr:nth-child(" + z + ") > td:nth-child(6)").innerText
} else {
if (document.querySelector("#table-list > tr:nth-child(" + z + ") > td:nth-child(5)").innerText != '-') {
a[v][4] = 0
a[v][5] = document.querySelector("#table-list > tr:nth-child(" + z + ") > td:nth-child(5)").innerText
a[v][6] = document.querySelector("#table-list > tr:nth-child(" + z + ") > td:nth-child(6)").innerText
} else {
a[v][4] = 2
a[v][5] = '-'
a[v][6] = '-'
}
}
a[v][7] = document.querySelector("#table-list > tr:nth-child(" + z + ") > td:nth-child(7)").innerText
console.log("page num " + b + " element num " + z + " filling array of " + v + " | " + a[v][0])
}
}
}