BaseSgmlLinkExtractor: Fix extract '>>' as '>'

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

Signed-off-by: Ping Yin <pkufranky@gmail.com>
This commit is contained in:
Ping Yin 2010-09-19 19:28:35 -03:00
parent f41fd3214e
commit aa86f180b9
2 changed files with 4 additions and 2 deletions

View File

@ -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

View File

@ -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):