我正在尝试在此处运行一个简单的cheerio抓取脚本:

      var $ = cheerio.load(body);
      var scoresTable = $('.grey').html();
      var scoresTableTbody = scoresTable('tbody');
      console.log(scoresTableTbody);


但是返回的是:

scoresTable is not a function

我还尝试将var scoresTable = $('.grey').html();更改为var scoresTable = $('.grey');,但存在相同的错误。

感谢任何帮助:)

最佳答案

scoresTable是字符串,不是函数。

假设grey是分配给表try的类,要获取对该元素的对象引用,然后使用.find()

var $ = cheerio.load(body);
var scoresTable = $('.grey');
var scoresTableTbody = scoresTable.find('tbody');
console.log(scoresTableTbody);

关于javascript - Javascript“不是函数”错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32475990/

10-11 13:31