[英]page.evaluate() with document.querySelectorAll() returns undefined or empty array
I am trying to scrape the web responses from this site https://chat.kuki.ai/ using Puppeteer.我正在尝试使用 Puppeteer 从该站点https://chat.kuki.ai/抓取 web 响应。 I have tried using
page.$eval
and page.$$eval
.我试过使用
page.$eval
和page.$$eval
。 I've also tried this, https://www.javaer101.com/en/article/17934751.html and, Puppeteer page.evaluate querySelectorAll return empty objects and, https://github.com/puppeteer/puppeteer/issues/489 . I've also tried this, https://www.javaer101.com/en/article/17934751.html and, Puppeteer page.evaluate querySelectorAll return empty objects and, https://github.com/puppeteer/puppeteer/issues/ 489 . Each time, I get either an
undefined
object or and empty array.每次,我都会得到一个
undefined
的 object 或空数组。 My current code is:我目前的代码是:
const botResponses = await page.evaluate((sel) => {
let elements = Array.from(document.querySelectorAll(sel));
let responses = elements.map(element => {
return element.innerText;
})
return responses;
}, ".pb-chat-bubble pb-chat-bubble__bot");
The code returns an empty list.该代码返回一个空列表。 The selector in the code is a valid selector and you can check on the website to confirm.
代码中的选择器是有效的选择器,您可以在网站上查看以确认。 Any help is appreciated!
任何帮助表示赞赏!
Have you tried using page.$$eval您是否尝试过使用page.$$eval
const botResponses = await page.$$eval(".pb-chat-bubble pb-chat-bubble__bot",el=>el.innerText)
It does the same thing you're doing above with less code它用更少的代码做你在上面做的同样的事情
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.