Marco Dinatsoli Marco Dinatsoli - 7 months ago 65
CSS Question

python scrapy get href using css selector

I want to get the href value.

I tried this:

Link = Link1.css('span[class=title] a::text').extract()[0]

but i just get the text inside the

how can i get the link inside the href please


What you're looking for is:

Link = Link1.css('span[class=title] a::attr(href)').extract()[0]

Since you're matching a span "class" attribute also, you can even write

Link = Link1.css('span.title a::attr(href)').extract()[0]

Please note that ::text pseudo element and ::attr(attributename) functional pseudo element are NOT standard CSS3 selectors. They're extensions to CSS selectors in Scrapy 0.20.