mirror of https://github.com/scrapy/scrapy.git
commit
4e9a43c228
|
|
@ -146,12 +146,12 @@ If you want to extract only first matched element, you can call the selector ``.
|
|||
|
||||
It returns ``None`` if no element was found:
|
||||
|
||||
>>> response.xpath('//div/[id="not-exists"]/text()').extract_first() is None
|
||||
>>> response.xpath('//div[@id="not-exists"]/text()').extract_first() is None
|
||||
True
|
||||
|
||||
A default return value can be provided as an argument, to be used instead of ``None``:
|
||||
|
||||
>>> sel.xpath('//div/[id="not-exists"]/text()').extract_first(default='not-found')
|
||||
>>> sel.xpath('//div[@id="not-exists"]/text()').extract_first(default='not-found')
|
||||
'not-found'
|
||||
|
||||
Notice that CSS selectors can select text or attribute nodes using CSS3
|
||||
|
|
|
|||
Loading…
Reference in New Issue