urllib.parse.urlparse()
urllib.parse.urlparse() is a Python function in the Urllib Module category. Parses a URL into its components (scheme, netloc, path, params, query, fragment). The syntax is urllib.parse.urlparse(urlstring, scheme="", allow_fragments=True). Returns: ParseResult named tuple. A typical example: from urllib.parse import urlparse
p = urlparse("https://example.com:8080/path?a=1&b=2#sec")
p.scheme # "https"
p.netloc # "example.com:8080"
p.path # "/path"
p.query # "a=1&b=2". A close sibling is urllib.request.urlopen(), which opens a URL for reading (like GET request). Returns a file-like response object. A close sibling is urllib.request.Request(), which creates an HTTP request with custom headers and method. A close sibling is urllib.parse.urlencode(), which encodes dictionary or sequence of pairs into a URL query string. A close sibling is urllib.parse.urljoin(), which constructs a full URL by combining a base URL with a relative URL. More about this category: URL handling — request, parse, urlopen, urlparse, urlencode, quote. Related Urllib Module entries: urllib.request.urlopen(), urllib.request.Request(), urllib.parse.urlencode(), urllib.parse.urljoin(), urllib.parse.quote(), urllib.parse.unquote().