-
Notifications
You must be signed in to change notification settings - Fork 1
/
helpers.js
37 lines (32 loc) · 937 Bytes
/
helpers.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
/**
*
* @param {import("puppeteer").Page} page
*/
exports.scrapePrice = page => {
return page.evaluate(() => {
return parseFloat(
document
.querySelector('.up > div:first-child > div,.down > div:first-child > div')
.textContent.replace(/,/g, '')
.replace(/\$/g, '')
)
})
}
/**
* @param {import("puppeteer").Page} page the Chromium page to block resources
* @param {string[]} skip the resource types to skip
* @param {function(string) : void} callback called when a resource is blocked, passes the blocked resource type
*/
exports.blockResources = async (page, skip, callback) => {
await page.setRequestInterception(true)
page.on('request', req => {
const resourceType = req.resourceType()
if (skip.includes(resourceType)) {
callback(resourceType)
req.abort()
} else {
req.continue()
}
})
}
exports.isLinux = () => process.platform === 'linux'