Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scrapy css selector: get text of all inner tags

Tags:

html

css

scrapy

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?

like image 432
Jgaldos Avatar asked Dec 05 '16 23:12

Jgaldos


People also ask

How do you use the selector in Scrapy?

Description. When you are scraping the web pages, you need to extract a certain part of the HTML source by using the mechanism called selectors, achieved by using either XPath or CSS expressions. Selectors are built upon the lxml library, which processes the XML and HTML in Python language.

How do you write XPath for Scrapy?

When you are using text nodes in a XPath string function, then use . (dot) instead of using .//text(), because this produces the collection of text elements called as node-set.

What is CSS selector in XPath?

What is a CSS Selector? Essentially, the CSS Selector combines an element selector and a selector value that can identify particular elements on a web page. Like XPath, CSS selector can be used to locate web elements without ID, class, or Name.


1 Answers

response.css('mytag *::text') 

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

like image 50
eLRuLL Avatar answered Sep 28 '22 04:09

eLRuLL