python scrapy获取href使用css选择器 [英] python scrapy get href using css selector

查看:2012
本文介绍了python scrapy获取href使用css选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得href值。

我尝试过:

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

但我只是得到< a> 内的文本。

but i just get the text inside the <a>.

推荐答案

您正在寻找的是:

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

c> span class属性,你甚至可以写

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

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



注意 :: text 伪元素和 :: attr(attributename)强>标准的CSS3选择器。它们是Scrapy 0.20中的CSS选择器的扩展。

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.

这篇关于python scrapy获取href使用css选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆