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());
});
});