How To Add Non-ascii Characters In Xpath, In Scrappy
I have the following Xpath: bathroom = response.xpath(“.//div[1][contains(., 'Baños’)]/text()').extract_first() And I get this error: ValueError: All strings must be XML comp
Solution 1:
Besides the literal Baños
, your code snippet contains invalid literal string delimiter (both single and double quotes) which will cause a different error :
bathroom = response.xpath(“.//div[1][contains(., 'Baños’)]/text()").extract_first()
^ ^
Converting the entire XPath expression to unicode, as suggested in the 2nd link, and fixing the two quotes pointed above should fix the initial errors. Below as a quick test using lxml
(which scrapy uses under the hood) :
>>>from lxml import etree>>>root = etree.fromstring('<root/>')>>>root.xpath(u".//div[1][contains(., 'Baños')]/text()")
[]
Post a Comment for "How To Add Non-ascii Characters In Xpath, In Scrappy"