-
Notifications
You must be signed in to change notification settings - Fork 0
/
getPlayersFromWorld.js
42 lines (35 loc) · 1.39 KB
/
getPlayersFromWorld.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
const puppeteer = require("puppeteer");
let getPlayersFromWorld = async world => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(
`https://www.tibia.com/community/?subtopic=worlds&world=${world}`
);
await page.waitFor(1000);
const result = await page.evaluate(() => {
let data = [];
let countPlayer = document.querySelectorAll(
"#worlds > div.Border_2 > div > div > div:nth-child(5) > table > tbody > tr > td > div > table > tbody > tr"
).length;
for (var i = 2; i < countPlayer; i++) {
let name = document.querySelector(
`#worlds > div.Border_2 > div > div > div:nth-child(5) > table > tbody > tr > td > div > table > tbody > tr:nth-child(${i}) > td:nth-child(1)`
).innerText;
let level = document.querySelector(
`#worlds > div.Border_2 > div > div > div:nth-child(5) > table > tbody > tr > td > div > table > tbody > tr:nth-child(${i}) > td:nth-child(2)`
).innerText;
let vocation = document.querySelector(
`#worlds > div.Border_2 > div > div > div:nth-child(5) > table > tbody > tr > td > div > table > tbody > tr:nth-child(${i}) > td:nth-child(3)`
).innerText;
data.push({
name: name,
level: level,
vocation: vocation
});
}
return data;
});
browser.close();
return result;
};
module.exports = getPlayersFromWorld;