JS Puppeteer wait for page load to complete

点点圈 提交于 2019-12-07 08:14:26

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!