xpath:
//ol[@class="breadcrumb container"]/li[not(contains(@class,"first")) and not(contains(@class,"last"))]/a/span/text()
HTML格式:
^{pr2}$Python代码:
categories = ['NO DATA', 'NO DATA', 'NO DATA', 'NO DATA', 'NO DATA', 'NO DATA']
catIndex = 0
for cat in sel.xpath('//ol[@class="breadcrumb container"]/li[not(contains(@class,"first")) and not(contains(@class,"last"))]/a/span/text()').extract():
categories[catIndex] = cat
catIndex += 1
想要的结果是“Books”,当我用xpath在Firebug控制台上检查它时,它会返回正确的结果,但是当我运行spider时,它返回整个3个Li元素,不排除^{cl1}$
我尝试了Scrapy Viewhttp://example.com命令来查看spider是如何看待它的,但一切看起来都是一样的,xpath返回了正确的结果
当我尝试在Scrapy Shell中使用xpath时,它返回所有3个Li元素的错误结果
有什么问题吗?在
在Internet Explorer中打开了废视图http://example.com输出,发现Li元素中没有Class属性。在
这说明在Chrome或Firefox中打开的Scrapy View命令并没有显示spider看到的真实代码。在
相关问题 更多 >
编程相关推荐