Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

135
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda