urllib.parse.urljoin(base, url)
If url is an absolute URL (that is, starting with //, http://, https://, ...), the url’s host name and/or scheme will be present in the
result. For example:
>>> urljoin('https://www.google.com', '//www.microsoft.com')
'https://www.microsoft.com'
>>>
otherwise, urllib.parse.urljoin(base, url) will
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.
>>> urlparse('http://a/b/c/d/e')
ParseResult(scheme='http', netloc='a', path='/b/c/d/e', params='', query='', fragment='')
>>> urljoin('http://a/b/c/d/e', 'f')
>>>'http://a/b/c/d/f'
>>> urlparse('http://a/b/c/d/e/')
ParseResult(scheme='http', netloc='a', path='/b/c/d/e/', params='', query='', fragment='')
>>> urljoin('http://a/b/c/d/e/', 'f')
'http://a/b/c/d/e/f'
>>>
it grabs the path of the first parameter (base), strips the part after the last / and joins with the second parameter (url).
If url starts with /, it joins the scheme and netloc of base with url
>>>urljoin('http://a/b/c/d/e', '/f')
'http://a/f'