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

83
Views
How to get first to fifth element's tag data with CheerIo

I scrape HTML data with CheerIO in Node.js.

And I got a HTML data like this. And I want to get all image src's data

<div class="owl-stage-outer">
    <div class="owl-stage">
        <div class="owl-item active">
            <div class="tb-thumb-item tb-selected">
                <a>
                    <img src="IMAGE URL">
                </a>
            </div>
        </div>
        <div class="owl-item active">
            <div class="tb-thumb-item">
                <a>
                    <img src="IMAGE URL">
                </a>
            </div>
        </div>
        <div class="owl-item active">
            <div class="tb-thumb-item ">
                <a>
                    <img src="IMAGE URL">
                </a>
            </div>
        </div>
        .........(Same owl-item classes)
    </div>
</div>

So I copy JS path from Chrome Developer Tool And I thought with this code it might work. But it only returns 'undefined'

await got(`${URL}`, {
    timeout: {
      request: 30000
    }
  }).then((response) => {
    const $ = cheerio.load(response.body);

console.log($('#thumblist > div.owl-stage-outer > div.olw-stage > div.owl-item:nth-child(1) > div.tb-thumb-item > a > img').attr('src'));

console.log($('#thumblist > div.owl-stage-outer > div.olw-stage > div.owl-item:nth-child(2) > div.tb-thumb-item > a > img').attr('src'));

console.log($('#thumblist > div.owl-stage-outer > div.olw-stage > div.owl-item:nth-child(3) > div.tb-thumb-item > a > img').attr('src'));

});

But it's really weird that this code works, but I need to get all of them but, this code only gets first element data.

console.log($('.tb-thumb .tb-thumb-item a > img:nth-child(1)').attr('src');
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!