【发布时间】:2020-09-17 19:47:21
【问题描述】:
我正在使用代码来获取元素,它可以完美运行并满足我的需求。但是,我意识到他没有拾取所有元素,因为他没有在屏幕上加载它们,并且要加载我需要向下滚动。
我搜索但找不到向下滚动以加载其他元素的方法,有人可以帮助我吗?
const puppeteer = require('puppeteer');
const acesso = require('./acesso');
(async () => {
const browser = await puppeteer.launch({
headless: false
});
const page = await browser.newPage()
await page.goto('https://www.instagram.com/')
await page.waitFor('input[name="username"]')
await page.type('input[name="username"]', acesso.dados.usuario, { delay: 100 })
await page.type('input[name="password"]', acesso.dados.senha, { delay: 100 })
await page.keyboard.press('Enter')
await page.waitForNavigation()
await page.click('#react-root > section > main > div > div > div > div > button')
await page.waitFor(10000)
await page.click('.aOOlW.HoLwm')
await page.goto('https://www.instagram.com/teamcarrascoo/')
await page.waitFor(10000)
await page.click('.RR-M-.h5uC0')
await page.waitFor(1000)
await page.click('.Igw0E.rBNOH.eGOV_._4EzTm')
page.waitFor(2000)
const hrefs = await page.$$eval('.xLCgt a', links => links.map(link => link.href));
hrefs.forEach((link, index) =>{
setTimeout(()=>{
page.goto(link)
},index * 10000)
})
})();
//The problem is in const hrefs = await page.$$eval('.xLCgt a', links => links.map(link => link.href)); I need to get all the elements, but only what was loaded on the screen comes, so I need to scroll it.
【问题讨论】:
-
我还是有问题。那么下面...使用下面的命令: window.scrollBy (0, window.innerHeight) 它完全滚动页面,但是,我想要故事栏,而不是页面。但是,如果我关闭故事并使用它可以工作的命令,那么当我打开故事查看器时,我的滚动条(向上和向下)不适用于该命令。你能帮我解决这个问题吗?
标签: javascript node.js puppeteer