Web scraping with cheerio not working with some elements


I just started learning about web scraping and I found this tutorial:
https://www.mundojs.com.br/2020/05/25/criando-um-web-scraper-com-nodejs/

It works fine, however I’m trying to get diferent elements from the same webpage: https://ge.globo.com/futebol/brasileirao-serie-a/

With the group of classes of the tutorial it brings all the elements with the selected class, but with other classes it doesn’t work:

enter image description here

As can be seen all fifty elements with the class ranking-item-wrapper are returned, but if I select the elements with the class lista-jogos__jogo it doesn’t return only one element, but there are ten of them:

enter image description here
enter image description here

This is the only one.

I don’t get why I’m getting this error, since I’m doing exectly the same thing as it is done in the tutorial.

Here is a shor version of the code:

const axios = require('axios');
const cheerio = require('cheerio');
const url = 'https://ge.globo.com/futebol/brasileirao-serie-a/';

axios(url).then(response => {
  const html = response.data;
  const $ = cheerio.load(html);
  console.log($('.ranking-item-wrapper')) // => tutorial class
  console.log('***')
  console.log($('.lista-jogos__jogo')) // => class that I'm using
}).catch(console.error);

Source: JavaSript – Stack Overflow

November 27, 2021
Category : News
Tags: axios | cheerio | javascript | node.js | web-crawler

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.