Skip to content

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

Move urlparsing statement in add_http_if_no_scheme()

Paul Tremberthfb8ab2427bff
diff --git a/scrapy/utils/url.py b/scrapy/utils/url.py
index 0e36003ad..0acbbb6ab 100644
--- a/scrapy/utils/url.py
+++ b/scrapy/utils/url.py
@@ -116,8 +116,8 @@ def escape_ajax(url):
def add_http_if_no_scheme(url):
"""Add http as the default scheme if it is missing from the url."""
match = re.match(r"^\w+://", url, flags=re.I)
- parts = urlparse(url)
if not match:
+ parts = urlparse(url)
scheme = "http:" if parts.netloc else "http://"
url = scheme + url