4

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?

1 Answer 1

4

As simple as list concatenation:

article['title'] = response.css("p.title ::text").extract() + \
                   response.css("span.newstitle ::text").extract()
Sign up to request clarification or add additional context in comments.

1 Comment

an even simpler: response.css("p.title ::text, span.newstitle ::text").extract()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.