相対URLを絶対URLに変換

2014年10月11日
1 分

urlparse.urljoin を使う。

>>> import urlparse
>>> base = "http://www.example.com/foo/bar/baz.html"
>>> relative = "../hoge/fuga.html"
>>> urlparse.urljoin(base, relative)
'http://www.example.com/foo/hoge/fuga.html'