all Python 3urllib.parsefunction
urllib.parse.urldefrag()
URL parsing
Cuts the fragment (the part after '#') off a URL and returns a pair: the address without the fragment and the fragment itself.
Syntax
url, fragment = urllib.parse.urldefrag(url)
The fragment is never sent to the server, so it is stripped before caching or comparing addresses. Without '#' the fragment is an empty string and the address is returned unchanged. The result is a DefragResult, so url, frag = urldefrag(u) works. The query string stays in url.
Examples
from urllib.parse import urldefrag
url, frag = urldefrag('http://h/p?q=1#sec')
print(url, frag) # → http://h/p?q=1 sec
print(repr(urldefrag('http://h/p').fragment)) # → ''
See also
Open in the full glossarydocs.python.orgReport an inaccuracy