Scrapy Selector 有 select() 方法?

Scrapy Selector has select() method?

虽然 运行 最新版本的 Scrapy 并使用 HtmlXPathSelector 进行我的 Xpath 提取,但我从日志中注意到 HtmlXPathSelector 已被弃用。

所以在将所需节点(让我们称之为 $myNode)更改为 Selector 实例而不是 HtmlXPathSelector 实例之后,我预计 $myNode.select() 会给出错误,因为,根据 the API,选择器 class 只有 xpath() 方法而不是 select() 方法。

然而 select() 方法继续发挥作用。实际上,如果我在 Selector 实例上执行 dir()select() 就在那里作为此 class.

的方法

这是 API 文档中的遗漏吗?或者它被故意遗漏,试图让用户根据他们的查询类型明确使用 xpath()css()

Read the source, Luke!

当您不确定时,请查看 source codeselect()被标记为"deprecated",应该使用xpath()代替:

@deprecated(use_instead='.xpath()')
def select(self, xpath):
    return self.xpath(xpath)

这是为了更顺利地过渡到较新的 Scrapy 版本而特意完成的。


注意,从0.24.0开始,Scrapy蜘蛛回调中可用的response变量有Selector的方法快捷方式:

def parse(self, response):
    response.xpath("//title/text()")
    response.css("div.content")

相关问题: