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

173
Views
Only getting parent divs axios

I have a problem with Axios and or Cheerio. I am trying to get all the divs from a web page but i only manage to get the parent divs.

Here is my code:

const axios = require("axios");
const cheerio = require("cheerio");

const slUrl = "https://sl.se/";

axios.get(slUrl).then((response) => {
  const $ = cheerio.load(response.data);
  $("div").each((index, element) => {
    const divClass = $(element).attr("class");
    console.log(divClass);
  });
});

The result of this is:

sl_fragment_header_1-18-1
undefined
sl_fragment_travel-planner_3-12-1
sl_fragment_travel-result_3-9-0
sl_fragment_departures_1-12-0
sl_fragment_traffic-situation-summary_1-4-0
sl_fragment_highlighted-teaser_1-0-4
sl_fragment_teasers_1-1-1
sl_fragment_traffic-news_1-0-0
sl_fragment_footer_1-9-0

These are the classes of the divs that i manage to collect. The problem is that when i visit this site and inspect the content, every one of these divs has child divs.

Here is an example of the div with class 'sl_fragment_travel-planner_3-12-1':

Travel planner div

I cannot manage to get these child divs. What am i missing here?

I forgot to mention that when I run the exact same code on https://www.aftonbladet.se i get all the divs.. Not only the parent divs...

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

0

The problem is that $("div") is only selecting the divs on the root level. you need to address the root div and all children divs.

There you should find your solution: select elements and all children

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!