-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscraper.js
32 lines (26 loc) · 1.01 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
const { chromium } = require('playwright')
async function scrapePrices() {
console.log('Running scraper...')
const browser = await chromium.launch({ headless: false })
const page = await browser.newPage()
await page.goto('https://www.dealabs.com')
await page.getByRole('button', { name: 'Tout accepter' }).click()
await page.getByRole('button', { name: 'Les + hot' }).click()
await page.waitForTimeout(1000)
const productOfTheDay = await page.evaluate(() => {
const productElement = document.querySelector('article[id^="thread_"]')
console.log('productElement', productElement)
if (productElement) {
return {
title: productElement.querySelector('.thread-title').textContent.trim(),
price: productElement.querySelector('.thread-price').textContent.trim(),
link: productElement.querySelector('a').href,
}
}
return null
})
await browser.close()
console.log('productOfTheDay', productOfTheDay)
return productOfTheDay
}
module.exports = scrapePrices