response.xpath('//*[has-class("on")]')
gives you the selector (all classes that have ‘on’)len(response.xpath('//*[has-class("on")]'))
gives you the length – in this case the number of classes
Solution 1 :
Problem :
How to use Scrapy to find out the number of classes with the word “on” in the class name?
<div class="listing item-rating" style="display: block;">
<img src="/Content/images/spacer.gif" class="star-left on">
<img src="/Content/images/spacer.gif" class="star-right on">
<img src="/Content/images/spacer.gif" class="star-left on">
<img src="/Content/images/spacer.gif" class="star-right of">
<img src="/Content/images/spacer.gif" class="star-left of">
<img src="/Content/images/spacer.gif" class="star-left of">
</div>