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

99
Visualizações
Puppeteer renders ALL HTML Content but only gets some tags

I am web scraping using NodeJS/typescript.

I have a problem using puppeteer where I get the fully rendered page (which I verify by running await page.content()). I printed the content and found that it had 26 'a' tags (links). However, when I search with puppeteer, I only get 20.

What is more strange is that sometimes I will get all the 'a' tags on the page and sometimes it gets less 'a' tags than on the page - all without changing the code! It seems to be kind of random.

I've seen some suggestions online saying to use a waitForElement method or something along those lines. Basically, before searching for tags, it ensures an element is on the page. I don't think this would help in my case because clearly puppeteer is getting everything it needs as shown by the await page.content() method.

Does anyone know why this may be happening? Thanks! A simplified snippet of my code is below.

const getLinksFromPage = async (
    browser: puppeteer.Browser,
    url: string
) => {
    const page = await browser.newPage();

    const curLink = book.sportsURLs[pageIndex];
    await page.goto(url, { waitUntil: 'networkIdle0'});

    const html = await page.content();    // this code gets the content and prints it 
    console.log(html);                    // so I can verify number of 'a' tags

    const rawLinks = await page.$$eval('a', (elements: Element[]) => {
        return elements
            .map((element: Element) => element.getAttribute('href')!)
    });

    await page.close();
    return rawLinks
};
about 4 years ago · Juan Pablo Isaza
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