小编Fur*_*dew的帖子

Cheerio 错误,未定义不是函数 // 这是正确的方法吗?

尝试运行代码时,我不断收到错误$.find('.market_listing_item_name_block').each()- undefined 不是函数,指向 find。我认为 find 是cheerio中的一个函数?公平地说,我不确定我是否做对了,这是我的代码:

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)
    })
})
Run Code Online (Sandbox Code Playgroud)

xhr 是一个本质上类似于 AJAX 的对象。

我之前在 chrome 中的做法是:

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)
})
Run Code Online (Sandbox Code Playgroud)

进而:

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
})
Run Code Online (Sandbox Code Playgroud)

我究竟如何才能在 node/cheerio 中重新创建那个 ^?我相信我显然错过了几步。非常感谢任何帮助,谢谢。

node.js cheerio

5
推荐指数
1
解决办法
3811
查看次数

标签 统计

cheerio ×1

node.js ×1