Cheerio 查找嵌套 table 中的所有链接

Cheerio find all links in nested table

我正在尝试检索特定 table 中的所有链接,但选择器似乎不起作用。当我将输出记录到控制台时,什么也没有出现,我做错了什么?

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, 2.0.0-2.9.0, and 1.0.1, 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);
});