Scrapy css selector: get text of all inner tags

Jgaldos picture Jgaldos · Dec 6, 2016 · Viewed 16k times · Source

I have a tag and I want to get all the text inside available. I am doing this:

response.css('mytag::text')

But it is only getting the text of the current tag, I also want to get the text from all the inner tags.

I know I could do something like:

response.xpath('//mytag//text()')

But I would like to do it with css selectors. How can I achieve this?

Answer

eLRuLL picture eLRuLL · Dec 6, 2016
response.css('mytag *::text')

The * will visit all the inner tags of mytag and ::text will get the text of each of them