1>>> from urllib.parse import urljoin
2>>> urljoin('/media/path/', 'js/foo.js')
3'/media/path/js/foo.js'
4
1from urllib.parse import urlparse, parse_qs
2URL='https://someurl.com/with/query_string?i=main&mode=front&sid=12ab&enc=+Hello'
3parsed_url = urlparse(URL)
4parse_qs(parsed_url.query)
1>>> urllib.parse.urlparse("http://example.com/pa/th;param1=foo;param2=bar?name=val#frag")
2ParseResult(scheme='http', netloc='example.com', path='/pa/th', params='param1=foo;param2=bar', query='name=val', fragment='frag')
3
1Parse a URL into 5 components:
2<scheme>://<netloc>/<path>?<query>#<fragment>
3Return a 5-tuple: (scheme, netloc, path, query, fragment).
4Note that we don't break the components up in smaller bits
5(e.g. netloc is a single string) and we don't expand % escapes.