抓取页面后,我使用cheerio选择了表的页脚:
const $ = cheerio.load(data);
const foot = $('#tblAcctBal > tfoot > tr');
o = $(foot).html();
console.log(o);
结果显示为以下html:
tr> <th rowspan=\"1\" colspan=\"1\"></th>
<th rowspan=\"1\" colspan=\"1\"></th>
<th rowspan=\"1\" colspan=\"1\"></th>
<th rowspan=\"1\" colspan=\"1\"></th>
<th rowspan=\"1\" colspan=\"1\"></th>
<th rowspan=\"1\" colspan=\"1\">$0.00</th>
<th rowspan=\"1\" colspan=\"1\">$0.00</th>
<th rowspan=\"1\" colspan=\"1\">$0.00</th>
<th rowspan=\"1\" colspan=\"1\">$0.00</th>
<th rowspan=\"1\" colspan=\"1\">$0.00</th>undefined</tr>\n
我正在尝试获取页脚中的文本值数组。我尝试过:
$(foot).each( function (th) {
console.log($(th).text().trim())
})
但没有输出,怎么解决
2条答案
按热度按时间xwbd5t1u1#
选择
th
元素并在这些元素上循环。顺便说一句,cheerio中的
.each()
和其他迭代函数在函数签名中提供了index
和element
。在示例代码中,选择器返回一个
tr
元素,它需要类似.children()
的内容来获取每个th
元素。46scxncf2#
如果他们真在那里,你可以做: