I am scraping bing search results using node and cheerio. I need to grab all the href values from two lists that have different IDs.
- How can I grab all the tags from both these lists in one statement? I tried but it didn't work.
- From the first list, I do not want the li tags with the class "b_pag". How can I write a selector for it? Like a Not condition or something.
$("a", ["#b_content", "#b_context"]).each((index, element) => { const href = $(element).attr("href"); links.push(href); });
Refer to the attached screenshot for the html.html
Update2 : I was wanting to ignore the whole <li class="b_pag">
tag, but the solutions I found here and elsewhere ignored just that tag. Any other <li>
tag under it, which has any other or no class, does not get ignored.
I found a way around it. I could grab the <li>
tags that have other class names. Check out the html here. I am thinking of using four different selectors for the first four classes. Like $(.b_algo)
or $(.b_ans)
. But how can I grab the other two <li>
tags that have multiple classes associated with it? I could not get a clear idea from the cheerio docs. Hope I am clear enough for you guys! Something like $(.b_ans b_mop)
didn't work. Nor did $("li[class=b_ans b_mop")
.