Node.js 木偶演员:如何识别,水疗已经到达了它的底部,并且不可能再向下滚动?
我正在为Nodejs中的puppeter构建一个抽象/简化程序,以获取单页应用程序。它将执行的基本操作之一是多次向下滚动页面,以触发AJAX调用。我所做的基本上是:Node.js 木偶演员:如何识别,水疗已经到达了它的底部,并且不可能再向下滚动?,node.js,puppeteer,Node.js,Puppeteer,我正在为Nodejs中的puppeter构建一个抽象/简化程序,以获取单页应用程序。它将执行的基本操作之一是多次向下滚动页面,以触发AJAX调用。我所做的基本上是: (()=>{ page.on('response', async res => { if (res.includes('/someAjaxAction')) { numResponses++ } }) while(numResponses<20){ await scro
(()=>{
page.on('response', async res => {
if (res.includes('/someAjaxAction')) {
numResponses++
}
})
while(numResponses<20){
await scrollDown();//Calling my function that scrolls down.
await Promise.delay(400)//Creating a delay just in case...
}
})()
(()=>{
page.on('response',async res=>{
if(res.includes('/someAjaxAction')){
numResponses++
}
})
虽然(numResponses没有万无一失的方法,但我按照这个顺序处理无穷大
- 从目标收集数据
- 删除目标元素
- 滚动一段特定的时间
- 等待新的目标元素出现
- …循环通过,直到没有剩余内容
知道它完成的最简单方法是巧妙地使用try…catch
forpage.waitFor
函数。这对您有用吗?wait page.waitFor(()=>(window.innerHeight+window.pageYOffset)>=document.body.offtheight-2)
你能检查这个答案并用各种代码相应地更新你的帖子吗?