与浏览器控制台xpath resu相比,Scrapy spider返回的值不同

2024-10-02 14:16:25 发布

您现在位置:Python中文网/ 问答频道 /正文

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 view

当我尝试在Scrapy Shell中使用xpath时,它返回所有3个Li元素的错误结果

Scrapy Shell

有什么问题吗?在


Tags: andnodatacontainernotlixpathclass

热门问题