From 4caadf6b67e28aa213b3a8efc29e03fafc5ae73f Mon Sep 17 00:00:00 2001 From: Pablo Hoffman Date: Sun, 29 Jun 2008 06:08:48 +0000 Subject: [PATCH] added (yet another) xml node iterator based entirely in regex --HG-- extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%4030 --- scrapy/trunk/scrapy/xpath/iterator.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/scrapy/trunk/scrapy/xpath/iterator.py b/scrapy/trunk/scrapy/xpath/iterator.py index 5d483914e..9d7d98803 100644 --- a/scrapy/trunk/scrapy/xpath/iterator.py +++ b/scrapy/trunk/scrapy/xpath/iterator.py @@ -114,3 +114,19 @@ class expat_XMLNodeIterator(): start, end = self._byte_offset_buffer.pop(0) yield response_body[start:end] self._parser.Parse('', 1) + + +# TESTING (pablo) # +# Yet another node iterator: this one is based entirely on regular expressions, +# which means it should be faster but needs some profiling to confirm. + +class re_XMLNodeIterator(): + + def __init__(self, response, node): + self.response = response + self.node = node + self.re = re.compile(r"<%s[\s>].*?" % (node, node), re.DOTALL) + + def __iter__(self): + for match in self.re.finditer(self.response.body.to_string()): + yield XmlXPathSelector(text=match.group()).x('/' + self.node)[0]