Scrapy, a fast high-level web crawling & scraping framework for Python.
Handle badformed tags with no trailing >
Martin Olveyra0ba9999cca65
diff --git a/scrapy/contrib/ibl/htmlpage.py b/scrapy/contrib/ibl/htmlpage.pyindex 023030bdc..30c21c043 100644--- a/scrapy/contrib/ibl/htmlpage.py+++ b/scrapy/contrib/ibl/htmlpage.py@@ -81,7 +81,7 @@ class HtmlTag(HtmlDataFragment):return str(self)_ATTR = "((?:[^=/>\s]|/(?!>))+)(?:\s*=(?:\s*\"(.*?)\"|\s*'(.*?)'|([^>\s]+))?)?"-_TAG = "<(\/?)(\w+(?::\w+)?)((?:\s+" + _ATTR + ")+\s*|\s*)(\/?)>"+_TAG = "<(\/?)(\w+(?::\w+)?)((?:\s+" + _ATTR + ")+\s*|\s*)(\/?)>?"_DOCTYPE = r"<!DOCTYPE.*?>"_SCRIPT = "(<script.*?>)(.*?)(</script.*?>)"_COMMENT = "(<!--.*?-->)"diff --git a/scrapy/tests/test_contrib_ibl/test_extraction.py b/scrapy/tests/test_contrib_ibl/test_extraction.pyindex f79c9dc78..e9ce86f7e 100644--- a/scrapy/tests/test_contrib_ibl/test_extraction.py+++ b/scrapy/tests/test_contrib_ibl/test_extraction.py@@ -516,7 +516,7 @@ ANNOTATED_PAGE19 = u"""<div><p data-scrapy-annotate="{"variant": 0, "annotations": {"content": "name"}}">Product name</p><p data-scrapy-annotate="{"variant": 0, "annotations": {"content": "price"}}">60.00</p>-<img data-scrapy-annotate="{"variant": 0, "annotations": {"src": "image_urls"}}"src="image.jpg" />+<img data-scrapy-annotate="{"variant": 0, "annotations": {"src": "image_urls"}}" src="image.jpg" /><p data-scrapy-annotate="{"variant": 0, "required": ["description"], "annotations": {"content": "description"}}">description</p></div></body></html>diff --git a/scrapy/tests/test_contrib_ibl/test_htmlpage.py b/scrapy/tests/test_contrib_ibl/test_htmlpage.pyindex cdba56853..b3bc91fa5 100644--- a/scrapy/tests/test_contrib_ibl/test_htmlpage.py+++ b/scrapy/tests/test_contrib_ibl/test_htmlpage.py@@ -137,3 +137,13 @@ class TestParseHtml(TestCase):parsed = list(parse_html("<IMG SRC='http://images.play.com/banners/SAM550a.jpg' align='left' / hspace=5>"))self.assertEqual(parsed[0].attributes, {'src': 'http://images.play.com/banners/SAM550a.jpg', \'align': 'left', 'hspace': '5', '/': None})++ def test_no_ending_body(self):+ """Test case when no ending body nor html elements are present"""+ parsed = [_decode_element(d) for d in PARSED7]+ self._test_sample(PAGE7, parsed)++ def test_malformed(self):+ """Test parsing of some malformed cases"""+ parsed = [_decode_element(d) for d in PARSED8]+ self._test_sample(PAGE8, parsed)diff --git a/scrapy/tests/test_contrib_ibl/test_htmlpage_data.py b/scrapy/tests/test_contrib_ibl/test_htmlpage_data.pyindex 62cd6b526..39771a666 100644--- a/scrapy/tests/test_contrib_ibl/test_htmlpage_data.py+++ b/scrapy/tests/test_contrib_ibl/test_htmlpage_data.py@@ -246,3 +246,12 @@ PARSED7 = [{'end': 99, 'start': 85},]+PAGE8 = u"""<a href="/overview.asp?id=277"><img border="0" src="/img/5200814311.jpg" title=\'Vinyl Cornice\'</a></td><table width=\'5\'>"""++PARSED8 = [+ {'attributes' : {u'href' : u"/overview.asp?id=277"}, 'end': 31, 'start': 0, 'tag': u'a', 'tag_type': 1},+ {'attributes' : {u'src' : u"/img/5200814311.jpg", u'border' : u"0", u'title': u'Vinyl Cornice'}, 'end': 94, 'start': 31, 'tag': u'img', 'tag_type': 1},+ {'attributes' : {}, 'end': 98, 'start': 94, 'tag': u'a', 'tag_type': 2},+ {'attributes' : {}, 'end': 103, 'start': 98, 'tag': u'td', 'tag_type': 2},+ {'attributes' : {u'width': u'5'}, 'end': 120, 'start': 103, 'tag': u'table', 'tag_type': 1}+]