2

I am trying to retrieve all links in a specific table but the selector does not seem to work. When I log the output to the console nothing appears, what am I doing wrong?

NodeJS code :

  $ = cheerio.load(body);
            $("#TableWithRules").find("a").each(function(i, link){
                if(i == 10) return;
                console.log($(link).text() , $(link).attr('href'), true);
                
            });

The HTML code :

<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>

1 Answer 1

2

Looks like your selector is wrong, try it with:

$("#TableWithRules > table > tbody > tr > td").find("a").each(function(i, link){
    console.log($(link).text() , $(link).attr('href'), true);
});
3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.