mirror of https://github.com/scrapy/scrapy.git
Fix extract_first() docs
This commit is contained in:
parent
012211accd
commit
127c6c694a
|
|
@ -139,15 +139,15 @@ method, as follows::
|
|||
>>> response.xpath('//title/text()').extract()
|
||||
[u'Example website']
|
||||
|
||||
If you want to extract only first matched element, you must call the selector ``.extract_first()``
|
||||
If you want to extract only first matched element, you can call the selector ``.extract_first()``
|
||||
|
||||
>>> sel.xpath('//ul/li').extract_first()
|
||||
u'First list element'
|
||||
>>> sel.xpath('//div[@id="images"]/a/text()').extract_first()
|
||||
u'Name: My image 1 '
|
||||
|
||||
It returns ``None`` if no element was found:
|
||||
|
||||
>>> sel.xpath('//ul/li[999]').extract_first()
|
||||
None
|
||||
>>> sel.xpath('//div/[id="not-exists"]/text()').extract_first() is None
|
||||
True
|
||||
|
||||
Notice that CSS selectors can select text or attribute nodes using CSS3
|
||||
pseudo-elements::
|
||||
|
|
|
|||
Loading…
Reference in New Issue