def normalize_url(url):
"""
:param url:
:return:
"""
# only hostname
if not '/' in url:
return 'http://{}'.format(url)
p = urlparse.urlsplit(url)
# www.test.com/index.php
# exclude /xxxxx/index.php
if not p.netloc:
if url.startswith('/'):
# /xxxxx/index.php
return ''
else:
# www.test.com/index.php
return 'http://{}'.format(url)
# //www.test.com/index.php
if not p.scheme:
url = urlparse.urlunsplit(('http', p.netloc, p.path or '/', p.query, p.fragment))
return url
评论列表
文章目录