-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscraper_utils.js
More file actions
30 lines (24 loc) · 1.04 KB
/
scraper_utils.js
File metadata and controls
30 lines (24 loc) · 1.04 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
const { PendingXHR } = require('pending-xhr-puppeteer');
async function getTextByCssSelector(page, selector) {
const element = await page.$(selector);
return await (await element.getProperty('textContent')).jsonValue();
}
async function clickButton(page, selector, selectorLoading) {
await page
.waitForSelector(selector);
await page
.evaluate((cssSelector) => {document.querySelector(cssSelector).click()}, selector);
await waitForAllXhrFinished(page, selectorLoading)
}
async function waitForAllXhrFinished(page, selectorLoading) {
let pendingXHR = await new PendingXHR(page);
if (Number(pendingXHR.pendingXhrCount()) != 0) {
await pendingXHR.waitForAllXhrFinished();
}
if (selectorLoading) {
await page.waitForFunction("document.querySelector('"+selectorLoading+"').getAttribute('style') == 'display: none;'");
}
}
module.exports.getTextByCssSelector = getTextByCssSelector;
module.exports.clickButton = clickButton;
module.exports.waitForAllXhrFinished = waitForAllXhrFinished;