fix ValueError: Invalid XPath: //div/[id="not-exists"]/text() on selectors.rst

>>> response.xpath('//div/[id="not-exists"]/text()').extract_first() is None
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/vagrant/.virtualenvs/scrapy/lib/python2.7/site-packages/scrapy/http/response/text.py", line 109, in xpath
    return self.selector.xpath(query)
  File "/home/vagrant/.virtualenvs/scrapy/lib/python2.7/site-packages/scrapy/selector/unified.py", line 100, in xpath
    raise ValueError(msg if six.PY3 else msg.encode("unicode_escape"))
ValueError: Invalid XPath: //div/[id="not-exists"]/text()
This commit is contained in:
Hoat Le 2015-10-07 15:43:02 +07:00
parent 91cbf97415
commit 4e66955411
1 changed files with 1 additions and 1 deletions

View File

@ -146,7 +146,7 @@ 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``: