如:一个论坛中,有置顶贴和普通贴,它们使用了不同的class,但这两类帖子都是需要的内容,需要同时爬下来

假设置顶贴class="top",普通贴class="common",则xpath写法为:

response.xpath('//div[contains(@class, "top") or contains(@class, "common")])

类似地,如果要抓取同时包含两个class的元素,则把其中的or改为and即可:

response.xpath('//div[contains(@class, "top") and contains(@class, "common")])

本文有参考:http://www.365jz.com/article/24244

相关文章:

  • 2021-10-29
  • 2022-12-23
  • 2022-12-23
  • 2021-10-14
  • 2022-12-23
  • 2021-12-13
  • 2021-12-26
  • 2021-12-26
猜你喜欢
  • 2021-06-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-22
相关资源
相似解决方案