如何使用Scrapy找出具有相同名称的类数?

问题描述 投票:0回答:1

如何使用Scrapy找出班级名称中带有单词“ on”的班级数量?

<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>
python html dom scrapy css-selectors
1个回答
0
投票
  • response.xpath('//*[has-class("on")]')为您提供选择器(所有具有'on'的类)
  • [len(response.xpath('//*[has-class("on")]'))为您提供长度-在这种情况下,是课程数量
© www.soinside.com 2019 - 2024. All rights reserved.