When trying to run code, i keep getting the error $.find('.market_listing_item_name_block').each()
- undefined is not a function, pointing at find. I thought that find was a function in cheerio? To be fair, i'm not sure if i'm even doing this right, here is my code :
var cheerio = require('cheerio')
$ = cheerio.load('#searchResultsRows')
var url = 'http://steamcommunity.com/market/search?appid=730'
xhr.get(url).success(function(r){
$.find(".market_listing_item_name_block").each(function(){
var name = $(this).find(".market_listing_item_name").text();
console.log(name)
})
})
xhr is an object that essentially acts like AJAX.
the way i was doing it before in chrome, was:
var url = 'http://steamcommunity.com/market/search?appid=730'
var itemDiv = $("<div></div>")
$.get(url).success(function(r){
d = $(r).find('#searchResultsRows')
itemDiv.append(d)
})
and then:
itemDiv.find(".market_listing_item_name_block").each(function(){
var name = $(this).find(".market_listing_item_name").text();
console.log(name) // would normally do other things, but for the purpose of this post, i'm just console logging the name
})
how exactly would I be able to re-create that ^ in node/cheerio? I believe i'm missing a few steps obviously. any help is extremely appreciated, thanks.
When you get an element, you need to use wrap that element with $
before doing further selections
const $ = Cheerio.load(body)
const list = $('div.titles li')
list.each((index, li) => {
const title = $(li).find('p.title').text()
console.log(title)
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With