Scrapy, a fast high-level web crawling & scraping framework for Python.
Fix HtmlParserLinkExtractor and tests after #485 merge
Paul Tremberth8017d85d8a11
diff --git a/scrapy/contrib/linkextractors/htmlparser.py b/scrapy/contrib/linkextractors/htmlparser.pyindex aa68ce52f..6e3c5071a 100644--- a/scrapy/contrib/linkextractors/htmlparser.py+++ b/scrapy/contrib/linkextractors/htmlparser.py@@ -62,11 +62,12 @@ class HtmlParserLinkExtractor(HTMLParser):self.current_link = linkdef handle_endtag(self, tag):- self.current_link = None+ if self.scan_tag(tag):+ self.current_link = Nonedef handle_data(self, data):- if self.current_link and not self.current_link.text:- self.current_link.text = data.strip()+ if self.current_link:+ self.current_link.text = self.current_link.text + datadef matches(self, url):"""This extractor matches with any url, sincediff --git a/scrapy/tests/test_contrib_linkextractors.py b/scrapy/tests/test_contrib_linkextractors.pyindex 20a0dffde..de05cbe98 100644--- a/scrapy/tests/test_contrib_linkextractors.py+++ b/scrapy/tests/test_contrib_linkextractors.py@@ -317,7 +317,8 @@ class HtmlParserLinkExtractorTestCase(unittest.TestCase):[Link(url='http://example.com/sample2.html', text=u'sample 2'),Link(url='http://example.com/sample3.html', text=u'sample 3 text'),Link(url='http://example.com/sample3.html', text=u'sample 3 repetition'),- Link(url='http://www.google.com/something', text=u''),])+ Link(url='http://www.google.com/something', text=u''),+ Link(url='http://example.com/innertag.html', text=u'inner tag'),])class RegexLinkExtractorTestCase(unittest.TestCase):@@ -332,7 +333,8 @@ class RegexLinkExtractorTestCase(unittest.TestCase):self.assertEqual(lx.extract_links(self.response),[Link(url='http://example.com/sample2.html', text=u'sample 2'),Link(url='http://example.com/sample3.html', text=u'sample 3 text'),- Link(url='http://www.google.com/something', text=u''),])+ Link(url='http://www.google.com/something', text=u''),+ Link(url='http://example.com/innertag.html', text=u'inner tag'),])if __name__ == "__main__":