简体   繁体   English

为什么在 puppeteer page.evaluate 中的 console.log 不起作用?

[英]Why console.log in puppeteer page.evaluate doesn't work?

Got this function from another developer and i'm trying to debug it.从另一个开发人员那里得到了这个功能,我正在尝试调试它。 It's a web scraper based on puppeteer.这是一个基于 puppeteer 的网络爬虫。 But from some reason i can't console.log inside.但是由于某种原因我不能在里面 console.log 。

Can someone please point me to what am i'm missing here?有人可以指出我在这里缺少什么吗?

const getArticles = async (page) => {
  return await page.evaluate(() => {

  console.log('in page.evaluate')
//not printing anything in the console

    const products = document.querySelectorAll(".thumb-link")
    const formated = Array.from(products).map(x => x.href)
    console.log(22, formated)
    return Promise.resolve(formated.filter(x => x))
  });
}

let newArticles = await getArticles(page)

Add the following to see the browser's console log:添加以下内容以查看浏览器的控制台日志:

const page = await browser.newPage();
page.on('console', msg => console.log(msg.text()));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM