请查看以下html代码:
<header class="online">
<img src="http://static.flv.com/themes/h5/img/iconos/online.png"> <span>online</span>
<img src="http://static.flv.com/themes/h5/img/iconos/ojo16.png"> 428 <p>xxfantasia</p>
</header>
我想把文本放进去(在这个例子中是428)。我用这个:
def parse(self, response):
sel = Selector(response)
cams = sel.css('header.online')
for cam in cams:
print cam.css('text').extract()
我想我使用了正确的css选择器,但是得到的结果是空的。
有什么帮助吗?
CSS选择器don't normally have syntax to extract text content。
但是Scrapy使用
::text
伪元素扩展了CSS选择器,因此您希望使用cam.css('::text').extract()
,这应该与cam.xpath('.//text()').extract()
提供相同的功能注意:Scrapy还添加了
::attr(attribute_name)
函数伪元素来提取属性值(这在标准CSS选择器中也是不可能的)相关问题 更多 >
编程相关推荐