从this问题我了解到,scrapy extract_first()
类实例的方法Selector
可以接受可选参数default
,这非常有用。但是,我找不到任何描述此功能的相关official documentation。即使Selector's reference下的Selector objects也未提及它。也许extract_first()
有更多惊人的功能?有谁知道可以在哪里找到extract_first()
的完整描述?
答案 0 :(得分:5)
你可以在短语“
>之后的the documentation内找到它可以提供默认返回值作为参数,而不是使用None:
>>> response.xpath('//div[@id="not-exists"]/text()').extract_first(default='not-found')
'not-found'
另请注意,您可以在GitHub repository
上建议改进文档目前还没有extract_first
的另一个惊人功能,只有在找不到时才会设置默认值。