Skip to main content
 首页 » 编程设计

Python Scrapy extract_first() 文档

2025年05月04日22小虾米

来自 this问题 我了解到 scrapy Selector 类实例的方法 extract_first() 可以接受可选参数 default 这非常有用。但是,我找不到任何相关的 official documentation描述此功能。连Selector's reference在 Selector objects 下没有提到它。也许 extract_first() 有一些更惊人的功能?有谁知道在哪里可以找到 extract_first() 的完整描述?

请您参考如下方法:

其实你可以在the documentation里面找到它在短语之后:

A default return value can be provided as an argument, to be used instead of None:

>>> response.xpath('//div[@id="not-exists"]/text()').extract_first(default='not-found') 
'not-found' 

另请记住,您可以在 GitHub repository 上提出文档改进建议

目前 extract_first 没有其他惊人的功能,只有在找不到时才设置默认值。