Cheerio / nodeJS newbie here... save the vitriol for the real villains.
I am trying to extract the title (in this instance "Alfacash") from div class exchange-card-small-logo > a > img. There could be several instances of this div class in the HTML. I am trying to extract the title from each of the instances.
console.log won't get hit in the following:
axios.get("https://cryptoradar.co/exchanges")
.then(response => {
const html = response.data
const $ = cheerio.load(html)
$('.exchange-card-small-logo', html).each(function () {
console.log($(this).length)
})
And both of these log return 0:
const elems = $('.exchange-card-small-logo', html);
console.log(elems.length);
console.log(elems.toArray().length);
Also, this:
const elems = $('.exchange-card-small-logo', html);
console.log(elems);
returns:
LoadedCheerio {
length: 0,
options: { xml: false, decodeEntities: true },
_root: <ref *1> LoadedCheerio {
'0': Node {
type: 'root',
name: 'root',
parent: null,
prev: null,
next: null,
children: [Array],
'x-mode': 'no-quirks'
},
length: 1,
options: { xml: false, decodeEntities: true },
_root: [Circular *1]
},
prevObject: LoadedCheerio {
'0': Node {
type: 'root',
name: 'root',
parent: null,
prev: null,
next: null,
children: [Array]
},
length: 1,
options: { xml: false, decodeEntities: true },
_root: <ref *1> LoadedCheerio {
'0': [Node],
length: 1,
options: [Object],
_root: [Circular *1]
},
prevObject: LoadedCheerio {
length: 0,
options: [Object],
_root: [LoadedCheerio]
}
}
}
This is the CSS selector: #results > div > div.main-container.grid-flex > div:nth-child(1) > div.exchange-card-small-images > div.exchange-card-small-logo.
I can't get the hierarchy right all the way down to that div class using cheerio. Is there a way to filter out all instances of this class without traversing all the path?
The imgs are there in the html, I can see them.
$('.exchange-card-small-logo img').get().map(img => $(img).attr('title'))