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

133
Visualizações
How to check if children are of a certain tag with puppeteer

I'm trying to use Puppeteer to find prices from websites, and the way I'm doing it is running a $$eval and a set of if statements. I'm checking that there is a "$" in the innerText as well as a children.length of 0. This works decently, but there are sometimes children for just part of the string (i.e. a bold $ but a regular number). Is there any way to find out what tag the children are easily? I would like to check for no children having <div> tags. Below is my code:

var prices = await page.$$eval("div, span, p", (priceElements) => {
    var tmpPrices = [];
    for (var i = 0; i < priceElements.length; i++) {
      const priceIndex = priceElements[i].innerText.toLowerCase().indexOf("$");
      if (
        priceIndex > -1 &&
        priceElements[i].children.length == 0 &&
        priceElements[i].innerText.substring(priceIndex + 1).indexOf("$") == -1
      ) {
        tmpPrices.push(priceElements[i].innerText);
      }
    }
    return tmpPrices;
  });

And here's an example of when it doesn't work:

<div class="pricevalue1 accent-color1" style="font-size: 20px;">
   <b>
      <span class="currency-symbol">$</span>
      92,950
   </b>
</div>
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