diff --git a/scrapy/trunk/scrapy/tests/test_utils_xml.py b/scrapy/trunk/scrapy/tests/test_utils_xml.py index d12bffd99..1167c3667 100644 --- a/scrapy/trunk/scrapy/tests/test_utils_xml.py +++ b/scrapy/trunk/scrapy/tests/test_utils_xml.py @@ -34,6 +34,11 @@ class UtilsXmlTestCase(unittest.TestCase): self.assertEqual([x.x("@id").extract() for x in xpathselector_iternodes(response, 'product')], [['34017532'], ['34017557'], ['34017563'], ['34018057'], ['34018313'], ['34018599']]) + def test_iterator_text(self): + body = u"""onetwo""" + + self.assertEqual([x.x("text()").extract() for x in xpathselector_iternodes(body, 'product')], + [[u'one'], [u'two']]) if __name__ == "__main__": unittest.main() diff --git a/scrapy/trunk/scrapy/utils/xml.py b/scrapy/trunk/scrapy/utils/xml.py index 2d43c8b3a..acfa52363 100644 --- a/scrapy/trunk/scrapy/utils/xml.py +++ b/scrapy/trunk/scrapy/utils/xml.py @@ -19,6 +19,8 @@ def xpathselector_iternodes(obj, nodename): text = obj.body.to_unicode() elif isinstance(obj, str): text = obj.decode('utf-8') + else: + text = obj r = re.compile(r"<%s[\s>].*?" % (nodename, nodename), re.DOTALL) for match in r.finditer(text):