Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get class name using Scrapy

I am trying to get the products' ratings of a webpage. The rating is in <bl-rating>:

enter image description here

To get the title of the product, I did:

'title':product.css('h2::text').get()

Is there a way to get the rating (4.714...) using a similar technique?

like image 494
Soffamumie Avatar asked Sep 19 '26 16:09

Soffamumie


1 Answers

Rating isn't text node value rather attribute value.So You have to invoke ::attr(rating) instead of ::text to get that value as string/text.

'rating':product.css('bl-rating::attr(rating)').get()

Using an xpath expression:

After iterating over an array/list of elements, the subsequent xpath expression would be a relative expression (.//)

'rating':product.xpath('.//bl-rating/@rating').get()
like image 180
Md. Fazlul Hoque Avatar answered Sep 21 '26 05:09

Md. Fazlul Hoque



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!