<table cellspacing="0" cellpadding="0" width="90%" align="center" border="0">
<tr>
<td>
<table cellpadding="0" cellspacing="1" width="90%" border="0" align="center">
<tr>
<td
整个第二个表位于第一个表的td标记内。
我是新来的。我不能完全得到我的输出只给我内部表tr值。我有两张桌子,而且很乱。
$ = cheerio.load(html.toString());
var data = [];
$('tr').each(function(i, tr){
var children = $(this).children();
var itemNum = children.eq(0);
var row = {
"Num": itemNum.text().trim()
};
data.push(row);
console.log(row);
});
最佳答案
$ = cheerio.load(html.toString());
var data = [];
$('table tr td table tr').each(function(i, td){
var children = $(this).children();
var itemNum = children.eq(0);
var itemName = children.eq(1);
这段代码解决了这个问题。我不知道你只是把元素传递给你需要的元素,然后使用children.eq(n)我可以得到行中的每个td文本值。希望这能帮助其他人。