Solution 1 :

  • 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

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>

By

Leave a Reply

Your email address will not be published. Required fields are marked *