How do i select <a> with aria-label in cheerio?

Viewed 49

I am currently building a scraper which scrapes data from newspaper sites based on the keyword I am looking for, such as "environment" and "climate". But I have recently encountered a site where I couldn't simply check if the text has my desired keywords. Its HTML is written in this way

<a aria-label="Ravaged by floods, Bangladesh pitches plan to adapt to climate impacts" class="card-with-image-zoom" href="https://en.prothomalo.com/environment/climate-change/ravaged-by-floods-bangladesh-pitches-plan-to-adapt-to-climate-impacts">

Here is how i am looking for keywords using cheerio-

 const html = response.data;
            const $ = cheerio.load(html);
            const specificarticles = [];
$('a:contains("climate"),a:contains("environment")',HTML)

How do i check the keyword availability of this specific HTML using cheerio?

1 Answers

If it uses normal selectors, try

$("a[aria-label]") 

for all and

$("a[aria-label*=Bangladesh]") 

for example to get one with the word Bangladesh in it

Related