简体   繁体   English

page.evaluate() 和 document.querySelectorAll() 返回未定义或空数组

[英]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.$evalpage.$$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.

相关问题 PUPPETEER - 无法使用 page.evaluate(() => document.querySelectorAll()) 在某些网站上提取元素 - PUPPETEER - unable to extract elements on certain websites using page.evaluate(() => document.querySelectorAll()) Puppeteer page.evaluate querySelectorAll 返回空对象 - Puppeteer page.evaluate querySelectorAll return empty objects puppeteer page.evaluate() 返回空对象 - puppeteer page.evaluate() returns empty object 为什么 document.querySelectorAll 在这种情况下返回一个空数组? - Why does document.querySelectorAll return an empty array in this context? page.evaluate 或 page.$eval 在 Playwright 中总是返回 undefined - page.evaluate or page.$eval always returns undefined in Playwright document.querySelectorAll("body") 返回未定义 - document.querySelectorAll("body") returning undefined 使用网桥时,PhantomJS page.evaluate返回未定义 - PhantomJS page.evaluate returns undefined when using a bridge phantomjs:document.querySelectorAll() 不适用于动态页面 - phantomjs: document.querySelectorAll() not working for dynamic page document.querySelectorAll 返回的数组长度始终为 0 - Length of the array returned by document.querySelectorAll is always 0 document.querySelectorAll('body[direction="rtl"] td') 返回空列表,但 direction:rtl 是通过样式标签设置的 - document.querySelectorAll('body[direction="rtl"] td') returns empty list, but direction:rtl is set via style tag
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM