Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何迭代第n个未命名表的行_Jquery_Cheerio - Fatal编程技术网

Jquery 如何迭代第n个未命名表的行

Jquery 如何迭代第n个未命名表的行,jquery,cheerio,Jquery,Cheerio,我正在尝试使用ChereIO(类似于jQuery)来操作一个HTML页面,该页面的外观如下: <TABLE> <!--- table body --> </TABLE> <!-- more html --> <TABLE> <!--- another table body --> </TABLE> <!-- more html --> <TABLE> <TBODY>

我正在尝试使用ChereIO(类似于jQuery)来操作一个HTML页面,该页面的外观如下:

<TABLE>
<!--- table body -->
</TABLE>
<!-- more html -->
<TABLE>
<!--- another table body -->
</TABLE>
<!-- more html -->
<TABLE>
  <TBODY>
    <TR>
      <TD>Column 1 value</TD>
      <!-- similar cols 2-5 -->
    </TR>
    <!-- more rows -->
  </TBODY>
</TABLE>
<!-- rest of page -->
这不会产生任何输出

如果我记录
third.html()
,它将写入正确表的html。但我甚至不能计算其中的行数,更不用说深入到表单元格了。我已经看过了答案,但它们都是基于根的单个选择器。我真的不知道第三种数据类型是什么,或者如何操作它。

Cheerio的工作方式(或多或少)与jQuery相同。因此,如果您不确定如何在Cheerio中执行某些操作,我建议您查看jQuery文档。在任何情况下:请尝试以下操作:

$('table').eq(2).find("tr").each(function(i, row){
    console.log($(this).find('td').eq(0).html());
    console.log($(this).find('td').eq(2).html())
    console.log($(this).find('td').eq(4).html())
});

请看一看编辑后的文章,添加骨架html。似乎对我来说很好。正如预期的那样,输出是单个
0
。我也没有从jQuery文档中理解它。但这起了作用:)
$('table').eq(2).find("tr").each(function(i, row){
    console.log($(this).find('td').eq(0).html());
    console.log($(this).find('td').eq(2).html())
    console.log($(this).find('td').eq(4).html())
});