mirror of https://github.com/scrapy/scrapy.git
fixed bug with boolean results in lxml-based selectors
This commit is contained in:
parent
a8be54a8ea
commit
9b9ab37804
|
|
@ -55,7 +55,7 @@ class XPathSelector(object_ref):
|
|||
if hasattr(result, '__iter__'):
|
||||
result = [self.__class__(root=x, expr=xpath, namespaces=self.namespaces) \
|
||||
for x in result]
|
||||
elif result:
|
||||
else:
|
||||
result = [self.__class__(root=result, expr=xpath, namespaces=self.namespaces)]
|
||||
return XPathSelectorList(result)
|
||||
|
||||
|
|
|
|||
|
|
@ -45,6 +45,14 @@ class XPathSelectorTestCase(unittest.TestCase):
|
|||
self.assertEqual([x.extract() for x in xpath.select("concat(//input[@name='a']/@value, //input[@name='b']/@value)")],
|
||||
[u'12'])
|
||||
|
||||
@libxml2debug
|
||||
def test_selector_boolean_result(self):
|
||||
body = "<p><input name='a'value='1'/><input name='b'value='2'/></p>"
|
||||
response = TextResponse(url="http://example.com", body=body)
|
||||
xs = HtmlXPathSelector(response)
|
||||
self.assertEqual(xs.select("//input[@name='a']/@name='a'").extract(), [u'True'])
|
||||
self.assertEqual(xs.select("//input[@name='a']/@name='n'").extract(), [u'False'])
|
||||
|
||||
@libxml2debug
|
||||
def test_selector_same_type(self):
|
||||
"""Test XPathSelector returning the same type in x() method"""
|
||||
|
|
|
|||
Loading…
Reference in New Issue