0

How do I fetch specific <a> tags through cheerio and nodejs? In the following code I am trying to fetch #topstuff > div.card-section > div._hUb > a

, but when I am trying it's not returning anything.

var cheerio = require('cheerio');

var request = require('request');

var b;

request
({
    method: 'GET',
    url: 'https://images.google.com/searchbyimage?image_url=http://static2.jetpens.com/images/a/000/044/44756.jpg?s=8d7a25b1901bfcfddcd8a2210ad355d7'
}, function(err, response, body) {
    if (err) return console.error(err);
    $ = cheerio.load(body);
    $('div#topstuff').find('div.card-section > div._hUb > a').each(function (index, element, body) {
     var b = $(this).attr('href');
      console.log(b.text());

    }); 

});
thor
  • 21,418
  • 31
  • 87
  • 173
  • Please edit your question and add the missing information. I left a comment in the post body where the information is missing with additional information. – Sumurai8 May 07 '16 at 16:14
  • 2
    I suspect you need to evaluate the page content before trying to scrapping its structure. See this so http://stackoverflow.com/questions/15025800/executing-scraped-javascript-with-cheerio –  May 07 '16 at 16:21

0 Answers0