Scrapy, a fast high-level web crawling & scraping framework for Python.
fixed bug with boolean results in lxml-based selectors
Pablo Hoffman9b9ab378049a
diff --git a/scrapy/selector/lxmlsel.py b/scrapy/selector/lxmlsel.pyindex af5f765b4..55d1a48e6 100644--- a/scrapy/selector/lxmlsel.py+++ b/scrapy/selector/lxmlsel.py@@ -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)diff --git a/scrapy/tests/test_selector_lxml.py b/scrapy/tests/test_selector_lxml.pyindex b16a2e2bf..75375a57f 100644--- a/scrapy/tests/test_selector_lxml.py+++ b/scrapy/tests/test_selector_lxml.py@@ -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'])+@libxml2debugdef test_selector_same_type(self):"""Test XPathSelector returning the same type in x() method"""