如何解决Cheerio 查找嵌套表中的所有链接
我正在尝试检索特定表中的所有链接,但选择器似乎不起作用。当我将输出记录到控制台时,什么也没有出现,我做错了什么?
NodeJS 代码:
$ = cheerio.load(body);
$("#TableWithRules").find("a").each(function(i,link){
if(i == 10) return;
console.log($(link).text(),$(link).attr('href'),true);
});
HTML 代码:
<div id="TableWithRules">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td valign="top" nowrap="nowrap"><a GET THIS LINK ==> href="/cgi-bin/cvename.cgi?name=CVE-2020-5911">CVE-2020-5911</a></td>
<td valign="top">In versions 3.0.0-3.5.0,2.0.0-2.9.0,and 1.0.1,the NGINX Controller installer starts the download of Kubernetes packages from an HTTP URL On Debian/Ubuntu system.
</td>
</tr>
<tr>
<td valign="top" nowrap="nowrap"><a GET THIS LINK ==> href="/cgi-bin/cvename.cgi?name=CVE-2020-27730">CVE-2020-27730</a></td>
<td valign="top">In versions 3.0.0-3.9.0,the NGINX Controller Agent does not use absolute paths when calling system utilities.
</td>
</tr>
</table>
</div>
解决方法
看起来你的选择器有问题,试试:
$("#TableWithRules > table > tbody > tr > td").find("a").each(function(i,link){
console.log($(link).text(),$(link).attr('href'),true);
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。