Scrapy, a fast high-level web crawling & scraping framework for Python.
Use canonicalize_url in link extraction
Adrián Chaves35723d76c0c0
diff --git a/scrapy/linkextractors/lxmlhtml.py b/scrapy/linkextractors/lxmlhtml.pyindex fdfa92370..da525d52e 100644--- a/scrapy/linkextractors/lxmlhtml.py+++ b/scrapy/linkextractors/lxmlhtml.py@@ -9,7 +9,7 @@ from w3lib.url import canonicalize_urlfrom scrapy.link import Linkfrom scrapy.utils.misc import arg_to_iter, rel_has_nofollow-from scrapy.utils.python import unique as unique_list, to_unicode+from scrapy.utils.python import unique as unique_listfrom scrapy.utils.response import get_base_urlfrom scrapy.linkextractors import FilteringLinkExtractor@@ -66,7 +66,7 @@ class LxmlParserLinkExtractor(object):url = self.process_attr(attr_val)if url is None:continue- url = to_unicode(url, encoding=response_encoding)+ url = canonicalize_url(url, encoding=response_encoding)# to fix relative links after process_valueurl = urljoin(response_url, url)link = Link(url, _collect_string_content(el) or u'',diff --git a/tests/test_linkextractors.py b/tests/test_linkextractors.pyindex 38fb8fb4a..e9d6c0abe 100644--- a/tests/test_linkextractors.py+++ b/tests/test_linkextractors.py@@ -2,8 +2,6 @@ import reimport unittestfrom warnings import catch_warnings-import pytest-from scrapy.exceptions import ScrapyDeprecationWarningfrom scrapy.http import HtmlResponse, XmlResponsefrom scrapy.link import Link@@ -214,7 +212,7 @@ class Base:response = HtmlResponse("http://example.org/somepage/index.html", body=html, encoding='iso8859-15')links = self.extractor_cls(restrict_xpaths='//p').extract_links(response)self.assertEqual(links,- [Link(url='http://example.org/%E2%99%A5/you?c=%E2%82%AC', text=u'text')])+ [Link(url='http://example.org/%E2%99%A5/you?c=%A4', text=u'text')])def test_restrict_xpaths_concat_in_handle_data(self):"""html entities cause SGMLParser to call handle_data hook twice"""@@ -506,7 +504,6 @@ class LxmlLinkExtractorTestCase(Base.LinkExtractorTestCase):Link(url='http://example.org/item2.html', text=u'Pic of a dog', nofollow=False),])- @pytest.mark.xfaildef test_restrict_xpaths_with_html_entities(self):super(LxmlLinkExtractorTestCase, self).test_restrict_xpaths_with_html_entities()