Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

132
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!