Marco Dinatsoli Marco Dinatsoli - 1 year ago 146
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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download