Scrapy grab div with multiple classes?

后端 未结 2 2026
伪装坚强ぢ
伪装坚强ぢ 2021-02-20 04:14

I am trying to grab div\'s with the class: \'product\'. The problem is, some of the div\'s with class \'product\' also have the class \'product-small\'. So when I use xpat

2条回答
  •  感情败类
    2021-02-20 04:27

    You should consider using a CSS selector for this part of your query.

    http://doc.scrapy.org/en/latest/topics/selectors.html#when-querying-by-class-consider-using-css

    from scrapy import Selector
    sel = Selector(text='
    I am a product!
    ') print sel.css('.product').extract()

    If you need to, you can chain CSS and XPath selectors, as in the example on that page.

提交回复
热议问题