Skip to content
Permalink
Browse files

fix ValueError: Invalid XPath: //div/[id="not-exists"]/text() on sele…

…ctors.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()
  • Loading branch information
hoatle authored and dangra committed Dec 30, 2015
1 parent 7067117 commit ca8d60f2670adfba80fa1ef55446ed7f3463edca
Showing with 1 addition and 1 deletion.
  1. +1 −1 docs/topics/selectors.rst
@@ -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``:

0 comments on commit ca8d60f

Please sign in to comment.
You can’t perform that action at this time.