Skip to content

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

BaseSgmlLinkExtractor: Fix extract '>>' as '>' The anchor text is extracted as '>' in <a href="/">&gt;&gt;</a>

Ping Yinaa86f180b9a7
diff --git a/scrapy/contrib/linkextractors/sgml.py b/scrapy/contrib/linkextractors/sgml.py
index 17877031d..03b2028cb 100644
--- a/scrapy/contrib/linkextractors/sgml.py
+++ b/scrapy/contrib/linkextractors/sgml.py
@@ -71,8 +71,8 @@ class BaseSgmlLinkExtractor(FixedSGMLParser):
self.current_link = None
def 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 + data.strip()
def matches(self, url):
"""This extractor matches with any url, since
diff --git a/scrapy/tests/test_contrib_linkextractors.py b/scrapy/tests/test_contrib_linkextractors.py
index a5e57bde0..0adc257ef 100644
--- a/scrapy/tests/test_contrib_linkextractors.py
+++ b/scrapy/tests/test_contrib_linkextractors.py
@@ -14,6 +14,7 @@ class LinkExtractorTestCase(unittest.TestCase):
<p><a href="/about.html">About us</a></p>
<img src="/logo.png" alt="Company logo (not a link)" />
<p><a href="../othercat.html">Other category</a></p>
+ <p><a href="/">&gt;&gt;</a></p>
<p><a href="/" /></p>
</body></html>"""
response = HtmlResponse("http://example.org/somepage/index.html", body=html)
@@ -23,6 +24,7 @@ class LinkExtractorTestCase(unittest.TestCase):
[Link(url='http://example.org/somepage/item/12.html', text='Item 12'),
Link(url='http://example.org/about.html', text='About us'),
Link(url='http://example.org/othercat.html', text='Other category'),
+ Link(url='http://example.org/', text='>>'),
Link(url='http://example.org/', text='')])
def test_base_url(self):