After seeing this youtube video using puppeteer I got inspired to play a bit around with it. But I seem to have made the wrong choice of a website as a starter project.
const puppeteer = require('puppeteer')
;(async () => {
const browser = await puppeteer.launch()
const page = await browser.newPage()
await page.goto('http://www.produktresume.dk/AppBuilder/search?page=0')
page.once('load', () => {
const drugs = page
.evaluate(() =>
[...document.querySelectorAll('div.entity-link')].map(item => item)
)
.catch(err => console.log(err))
console.log(drugs[0])
})
await browser.close()
})()
I have googled around and lost track of the different things I have tried..
My perception of my problem is that I don't call the evaluate at the right time - when the page is loaded.
There is absolutely no need to use page.on('load')
to find if page loaded.
You can use the,
waitUntil
option on .goto
call.waitForSelector
function for specific selector.Usage,
await page.goto('http://www.produktresume.dk/AppBuilder/search?page=0', {waitUntil: 'networkidle0'});
await page.waitForSelector("#wrapper"); // Found on the page source code, wait for this to appear
// the rest is just as usual
const drugs = await page
.evaluate(() =>
[...document.querySelectorAll('div.entity-link')].map(item => item)
)
.catch(err => console.log(err))
console.log(drugs[0])
Make sure to use await
for the .evaluate
call.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With