-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscraper.js
62 lines (51 loc) · 2.06 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
const puppeteer = require('puppeteer');
(async () => {
const userInfo = {
country: 'us',
realm: 'area-52',
name: 'lukè',
};
let pageUrl = `https://raider.io/characters/${userInfo.country}/${
userInfo.realm}/${userInfo.name}#season=season-bfa-4`;
let browser = await puppeteer.launch({headless: false});
let page = await browser.newPage();
await page.setViewport({
width: 1920,
height: 1080,
});
await page.goto(pageUrl, {waitUntil: 'domcontentloaded'});
const agreeButtonSelector = '.qc-cmp2-summary-buttons button[mode=\"primary\"]';
//await agree button load
const watchDog = page.waitForFunction(`document.querySelector('${agreeButtonSelector}') !== null`);
await watchDog;
const cookieAccept = '.cookie-footer--accept_button';
//The issue of skipping some elemnts may reside in the cookie prompt
await (await page.$(agreeButtonSelector)).click();
setTimeout(() => {
}, 1000);
await (await page.$(cookieAccept)).click();
//creates a list of all twelve t-body's that need to be pressed
const tbodyList = await page.$$(".rio-striped");
//module clicks through all elements, currently only clicks first two
for (let i = 0; i < tbodyList.length; i++) {
const tbody = tbodyList[i];
await tbody !== null; //not sure if this is needed
// different delays seem to effect how each element is clicked
await new Promise(r => setTimeout(r, 3000)); //delay before scroll -> click
await tbody.click({ delay: 2000}); //after
}
//returns top ten dungeon times and parses string (incomplete parser, otherwise works)
let topDungeonTimes = await page.evaluate(() => {
let splitRecordsFull = [];
for (let i = 0; i < 12; i++) {
let dungeonRecords =
document.querySelectorAll('tbody[class="rio-striped"]')[i].innerText;
let splitRecords =
dungeonRecords.replaceAll('\t', ' ').replaceAll('\n', '').split(' ');
// add trim()
splitRecordsFull[i] = splitRecords.filter((el) => el !== ' ');
}
return splitRecordsFull;
});
await browser.close();
})();