Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

78
Visualizações
scrollIntoView() looping element on puppeteer

I want to scrape a list of posts while the page scroll is infinite loading. I want scrollIntoView() for each element in the loop. my code is temporarily like this and the result when the page is loaded, it bounces out but no error.

for (let i = 0; i < 20; i++) {
    const selector = 'div[role="feed"]:nth-child(2) div.sjgh65i0'

    await page.evaluate((selector, i) => {
      setTimeout(() => {
        const element = document.querySelectorAll(selector)[i]
        if(element) {
          element.scrollIntoView();
        }
      }, 2000);
    }, selector, i)
  }

For example, I want to take 20 posts and then the scraper will take the posts one by one.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

With your current flow, all timeouts are set almost at once and then all fire after the same 2 sec.

Try something like this:

const selector = 'div[role="feed"]:nth-child(2) div.sjgh65i0';

for (let i = 0; i < 20; i++) {
  await page.waitForTimeout(2000);

  await page.evaluate((selector, i) => {
    const element = document.querySelectorAll(selector)[i];
    if(element) {
      element.scrollIntoView();
    }
  }, selector, i);
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda