Search code examples
typescriptweb-scrapingcheerio

How can i get the href while using cheerio


I want to have the link while using cheerio with this code.

<div class="someClass">
    <a href="someLink">Link</a>
</div>

I have tried this but it doesn't work.

let link = $('.someClass a href').text();

Solution

  • You're trying to extract node text from attribute and it is not correct approach. If you want to extract attribute value try

    let link = $('.someClass a').attr('href');