In [1]:
# http://docs.python.jp/3.6/library/urllib.parse.html
In [2]:
import urllib.parse
In [3]:
values = {'key1': 'value1', 'key2': 'バリュー2'}
print(urllib.parse.urlencode(values))
In [4]:
base = 'http://example.com/sub1/index.html'
print(urllib.parse.urljoin(base, 'index2.html'))
print(urllib.parse.urljoin(base, '../../sub2/index.html'))
print(urllib.parse.urljoin(base, 'https://google.com'))
print(urllib.parse.urljoin(base, '//google.com'))
In [5]:
url = 'http://example.com/sub1/index.html?key=value'
o = urllib.parse.urlparse(url)
print(o)
print(o.scheme, o.netloc, o.path)
In [6]:
relative_url = 'sub/index.html'
o = urllib.parse.urlparse(relative_url)
print(o)