0

I'm beginner with cheerio, trying to implement a simple example to learn more about it. tried some solutions on Stackoverflow without success, for the beginning tried it on google website, just for my learn, marked the element I want with yellow, help some1 please?

my code:

const cheerio = require('cheerio');
const request = require('request');

request({
    method: 'GET',
    url: 'https://www.google.co.il/'
}, (err, res, body) => {

    if (err) return console.error(err);

    let $ = cheerio.load(body);

    $('div[class="gb_h gb_i"]').find('a').each(function (index, element) {
        console.log(element.attr(href));
      });

});

the elements in google:

enter image description here

ggorlen
  • 44,755
  • 7
  • 76
  • 106
NivKaduri
  • 41
  • 1
  • 3
  • 1
    If it's not on the dom, when you do `view-source:https://www.google.co.il/` then cheerio is no use, your need to use something like puppeteer instead – Lawrence Cherone May 06 '21 at 12:22
  • 1
    Thanks mate, helped me alot ! <3 – NivKaduri May 06 '21 at 12:35
  • Does this answer your question? [How can I scrape pages with dynamic content using node.js?](https://stackoverflow.com/questions/28739098/how-can-i-scrape-pages-with-dynamic-content-using-node-js) – ggorlen Jan 02 '23 at 18:46

0 Answers0