【问题标题】:Puppeteer - Facing Issue to scroll in-page content on linkedin sales navigatorPuppeteer - 在linkedin销售导航器上滚动页面内容时面临的问题
【发布时间】:2022-05-07 18:34:33
【问题描述】:
我正在尝试从 Linkedin Sales Navigator 中抓取一些公司及其潜在客户的详细信息。
我面临的问题是,代码只刮掉前 2-3 个名字。这个问题背后的原因是当页面滚动到底部时会动态添加潜在客户。该页面包含两个页内滚动条(以红色突出显示),我想为其中一个滚动条编写代码以滚动到其底部。
我要滚动的 div 部分有 class="p4 _vertical-scroll-results_1igybl".enter image description here。
如果有人可以使用 puppeteer 帮助我做到这一点,将不胜感激。
先谢谢了!!!
【问题讨论】:
标签:
node.js
scroll
puppeteer
【解决方案1】:
这是一个如何实现自动滚动的小示例:
let lastHeight = await page.evaluate("document.body.scrollHeight");
while (true) {
await page.evaluate("window.scrollTo(0, document.body.scrollHeight)");
await page.waitForTimeout(2000);
let newHeight = await page.evaluate("document.body.scrollHeight");
if (newHeight === lastHeight) {
break;
}
lastHeight = newHeight;
}
如果滚动在元素内部,则使用 document.querySelector("your_element") 代替 document.body。