Using multiple CSS selectors for the same ArticleI

2019-06-02 18:28发布

The site I am scraping has an inconsistent layout. I'm currently using this but its not returning all the titles -

article['title'] = sel.css('p[class=title] ::text').extract()

I need to use this to scrape span classes also -

article['title'] = sel.css('span[class=newstitle] ::text').extract()

Is there a way to combine two css selectors in a single ArticleItem?

标签: python scrapy
1条回答
甜甜的少女心
2楼-- · 2019-06-02 19:28

As simple as list concatenation:

article['title'] = response.css("p.title ::text").extract() + \
                   response.css("span.newstitle ::text").extract()
查看更多
登录 后发表回答