Edouard_W
Edouard_W

Reputation: 33

Scrapy - CSS selectors

I'm trying to understand how CSS selectors work using Scrapy. but I definitely don't understand to navigate in several html tag. For example, I'm trying to extract all the href link in the div id "portefeuille_bloc":

code screenshot

I tried this code but I can't identify where the mistake is:

response.css('div[id=portefeuille_bloc a::attr(href)').extract()

Furthermore, I tried to go deeper in the structure, and get all the h3 tag in the sub-division "portefeuille_bloc_bloc:

code screenshot

Upvotes: 0

Views: 637

Answers (2)

Ikram Khan Niazi
Ikram Khan Niazi

Reputation: 805

Try this:

response.css('#portefeuille_bloc ::attr(href)').extract()

There is no need to use HTML tags with ids and classes.

Upvotes: 0

Anthony Mills
Anthony Mills

Reputation: 8784

Try this:

response.css('div#portefeuille_bloc a::attr(href)').getall()

See this doc page for more ideas:

https://docs.scrapy.org/en/latest/topics/selectors.html

Upvotes: 1

Related Questions