0

How can I find all elements with class name starting with a certain string?

I know Cheerio can do things like $(".item") to get things with that exact class name. And I know you can do $("*:contains('hello')") to get all elements that has that string in the content.

But how do I filter based on part of the class name?

My first thought is to just scrape all the "divs" and apply a filter function afterwards, but that seems inefficient (or not? Is that what it would be doing anyway?) I'm looking for something like $("div:classStartsWith('ItemBox_')")

I looked at this question Extract class name in scrapy and it seems you can do it in python with response.css('.star-rating').xpath("@class").extract() . What is the equivalent of that in javascript and cheerio?

Qrow Saki
  • 932
  • 8
  • 19

0 Answers0