urlstd.parse.urlparse#
- urlstd.parse.urlparse(urlstring: str, base: str | None = None, encoding: str = 'utf-8', allow_fragments: bool = True) ParseResult #
An alternative to
urllib.parse.urlparse()
.Parses a string urlstring against a base URL base using the basic URL parser, and returns
urllib.parse.ParseResult
.- Parameters:
urlstring – An absolute-URL or a relative-URL. If urlstring is a relative-URL, base is required.
base – An absolute-URL for a relative-URL urlstring.
encoding – The encoding to encode URL’s query. If the encoding fails, it will be replaced with the appropriate XML character reference.
allow_fragments – If False, fragment identifiers are not recognized.
- Returns:
A named tuple
urllib.parse.ParseResult
.- Raises:
urlstd.error.URLParseError – Raised when URL parsing fails.
Examples
>>> urlparse('http://user:pass@foo:21/bar;par?b#c') ParseResult(scheme='http', netloc='user:pass@foo:21', path='/bar', params='par', query='b', fragment='c')
>>> urlparse('?🌈=a#c', base='http://user:pass@foo:21/bar;par?b#c') ParseResult(scheme='http', netloc='user:pass@foo:21', path='/bar', params='par', query='%F0%9F%8C%88=a', fragment='c')
>>> urlparse('?🌈=a#c', base='http://user:pass@foo:21/bar;par?b#c', ... encoding='windows-1252') ParseResult(scheme='http', netloc='user:pass@foo:21', path='/bar', params='par', query='%26%23127752%3B=a', fragment='c')