Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

handle case when attributes are not separated by space (still recognizable because of quotes)

Martin Olveyra32adbea545e4
diff --git a/scrapy/contrib/ibl/htmlpage.py b/scrapy/contrib/ibl/htmlpage.py
index 30c21c043..c86ec9670 100644
--- a/scrapy/contrib/ibl/htmlpage.py
+++ b/scrapy/contrib/ibl/htmlpage.py
@@ -80,8 +80,8 @@ class HtmlTag(HtmlDataFragment):
def __repr__(self):
return str(self)
-_ATTR = "((?:[^=/>\s]|/(?!>))+)(?:\s*=(?:\s*\"(.*?)\"|\s*'(.*?)'|([^>\s]+))?)?"
-_TAG = "<(\/?)(\w+(?::\w+)?)((?:\s+" + _ATTR + ")+\s*|\s*)(\/?)>?"
+_ATTR = "((?:[^=/<>\s]|/(?!>))+)(?:\s*=(?:\s*\"(.*?)\"|\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_htmlpage.py b/scrapy/tests/test_contrib_ibl/test_htmlpage.py
index b3bc91fa5..d85ae1afb 100644
--- a/scrapy/tests/test_contrib_ibl/test_htmlpage.py
+++ b/scrapy/tests/test_contrib_ibl/test_htmlpage.py
@@ -147,3 +147,9 @@ class TestParseHtml(TestCase):
"""Test parsing of some malformed cases"""
parsed = [_decode_element(d) for d in PARSED8]
self._test_sample(PAGE8, parsed)
+
+ def test_malformed2(self):
+ """Test case when attributes are not separated by space (still recognizable because of quotes)"""
+ parsed = [_decode_element(d) for d in PARSED9]
+ self._test_sample(PAGE9, parsed)
+
diff --git a/scrapy/tests/test_contrib_ibl/test_htmlpage_data.py b/scrapy/tests/test_contrib_ibl/test_htmlpage_data.py
index 39771a666..f54dc9f8c 100644
--- a/scrapy/tests/test_contrib_ibl/test_htmlpage_data.py
+++ b/scrapy/tests/test_contrib_ibl/test_htmlpage_data.py
@@ -255,3 +255,23 @@ PARSED8 = [
{'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}
]
+
+PAGE9 = u"""\
+<html>\
+<body>\
+<img width='230' height='150'src='/images/9589.jpg' >\
+<a href="/product/9589">Click here</a>\
+</body>\
+</html>\
+"""
+
+PARSED9 = [
+ {'attributes' : {}, 'end': 6, 'start': 0, 'tag': 'html', 'tag_type': 1},
+ {'attributes' : {}, 'end': 12, 'start': 6, 'tag': 'body', 'tag_type': 1},
+ {'attributes' : {'width': '230', 'height': '150', 'src': '/images/9589.jpg'}, 'end': 65, 'start': 12, 'tag': 'img', 'tag_type': 1},
+ {'attributes' : {'href': '/product/9589'}, 'end': 89, 'start': 65, 'tag': 'a', 'tag_type': 1},
+ {'end': 99, 'start': 89},
+ {'attributes' : {}, 'end': 103, 'start': 99, 'tag': 'a', 'tag_type': 2},
+ {'attributes' : {}, 'end': 110, 'start': 103, 'tag': 'body', 'tag_type': 2},
+ {'attributes' : {}, 'end': 117, 'start': 110, 'tag': 'html', 'tag_type': 2},
+]