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

170
Views
How To Select one of the same multiple elements in cheerio nodejs?

I'm trying to scrape links from a page, but the problem I'm facing right now is that i want to scrape href from anchor tag, but it has multiple tags with no class inside them.

It looks something like this

<div class="class1">
<a href="sample.com">Some random text</a>
<a href="example.com">Some random text</a>
</div>

Now I want to get example.com but when i try find(".class1").find("a").attr("href"); it returns me sample.com.

I want to do something like this to get example.com instead of sample.com find(".class1").find("a")[1].attr("href"); returns example.com

please someone help me with this. I'm a newbie to cheerio and cheerio's documentation is so much confusing to me.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can select the n-th <a> element using :

find(".class1").find("a:nth-child(4)").attr("href");
about 4 years ago · Juan Pablo Isaza Report
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!