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

192
Visualizações
Can't find any tags using NodeJS, puppeteer, and document.querySelector

I have a NodeJS Typescript project, and I am trying to get all the 'p' tags from a dynamically rendered website (not STATIC HTML but instead makes multiple requests to backend to get some data and render webpage). I am using typescript and have ["es6", "dom"] in my lib, and I have the following code (this is all my code in the project so far):

import puppeteer from 'puppeteer';

const getLinks = async () => {
    const browser = await puppeteer.launch();
    const [page] = await browser.pages();

    await page.goto('https://webscraper.io/test-sites', { waitUntil: 'networkidle0' });
    const links = await page.evaluate(() => document.querySelectorAll('p'));
    console.log(links);
    await browser.close();
}

However, I keep getting undefined when I print links. I assume this is because the program can't find any 'p' tags. Why is this?

Note: the url provided is just an example. I have tried across multiple different sites and I still get undefined.

Any help is appreciated! Thanks!

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

Don't use page.evaluate to get elements, use waitForSelector/waitForXpath/$x/$$ instead (see Puppeteer doc to know the differences between them: https://devdocs.io/puppeteer/index#pageselector-1):

const links: ElementHandle[] = await mainPage.$$("p");
about 4 years ago · Santiago Gelvez 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