mirror of https://github.com/scrapy/scrapy.git
added new test case for xpathselector_iternodes
--HG-- extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%4062
This commit is contained in:
parent
28b5bb3240
commit
49175d1990
|
|
@ -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"""<?xml version="1.0" encoding="UTF-8"?><products><product>one</product><product>two</product></products>"""
|
||||
|
||||
self.assertEqual([x.x("text()").extract() for x in xpathselector_iternodes(body, 'product')],
|
||||
[[u'one'], [u'two']])
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
|||
|
|
@ -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>].*?</%s>" % (nodename, nodename), re.DOTALL)
|
||||
for match in r.finditer(text):
|
||||
|
|
|
|||
Loading…
Reference in New Issue