从 Table Cheerio 获取文本

Chr*_*ord 4 javascript node.js cheerio

在处理网络抓取项目时,我无法以统一的方式获取某些数据。该页面有一个双列表,我只需要抓取第二列的文本即可运行编译值。

我正在这样做:

const rq = require('request');
const cheerio = require('cheerio');

rq(url, (err, res, html) => {
    let $ = cheerio.load(html);
    $('#table-id > tbody > tr > td.data').toArray().map(item => {
        console.log(item.text());
    });
});
Run Code Online (Sandbox Code Playgroud)

但是我收到一个.text()不是函数的错误。

Chi*_*ler 7

.text()是一种cheerio方法,因此要使用它,您需要使该项目成为cheerio元素

这应该有效:

console.log($(item).text())