archive about

urlparse.urljoin()

urlparse.urljoin(base, url[, allow_fragments])

Construct a full (“absolute”) URL by combining a “base URL” (base) with another URL (url). Informally, this uses components of the base URL, in particular the addressing scheme, the network location and (part of) the path, to provide missing components in the relative URL. For example:

>>> from urlparse import urljoin
>>> urljoin('http://www.cwi.nl/%7Eguido/Python.html', 'FAQ.html')
'http://www.cwi.nl/%7Eguido/FAQ.html'

It will also work with URLs, like this

>>> urljoin('http://blog.vrypan.net/2013/09/27/gnu-initial-announcement/', '../../../08/30/privacy-is-not-dead/')
'http://blog.vrypan.net/2013/08/30/privacy-is-not-dead/'