Parse a URL into five components, returning a 5-item named tupleSplitResult or SplitResultBytes.
This corresponds to the general structure of a URL:
scheme://netloc/path?query#fragment.
Each tuple item is a string, possibly empty, or None if
missing_as_none is true.
Not defined component are represented an empty string (by default) or
None if missing_as_none is true.
The delimiters as shown above are not part of the result, except for a
leading slash in the path component, which is retained if present.
If the allow_fragments argument is false, fragment identifiers are not
recognized. Instead, they are parsed as part of the path
or query component, and fragment is set to None or the empty
string (depending on the value of missing_as_none) in the return value.
返回值是一个 named tuple,这意味着它的条目可以通过索引或作为命名属性来访问,这些属性是:
在 3.16 版本发生变更: Passing an object that is not a string, bytes, or None as
urlstring or scheme now raises TypeError instead of
AttributeError.
自 3.16 版本弃用: Accepting objects with false values (like 0 and []) except empty
strings, byte-like objects and None as urlstring or scheme is
now deprecated. They will raise TypeError in Python 3.18.
根据 urlsplit() 返回的元组构造一个 URL。 parts 参数可以是任何包含五个条目的可迭代对象。
This may result in a slightly different, but equivalent URL, if the
URL that was parsed originally had unnecessary delimiters (for example,
a ? with an empty query; the RFC states that these are equivalent).
If keep_empty is true, empty strings are kept in the result (for example,
a ? for an empty query), only None components are omitted.
This allows rebuilding a URL that was parsed with option
missing_as_none=True.
By default, keep_empty is true if parts is the result of the
urlsplit() call with missing_as_none=True.
在 3.15 版本发生变更: 增加 keep_empty 形参。
在 3.16 版本发生变更: Passing an object that is not a string, bytes, or None in parts
now raises TypeError instead of AttributeError.
自 3.16 版本弃用: Accepting objects with false values (like 0 and []) except empty
strings, byte-like objects and None in parts is now deprecated.
They will raise TypeError in Python 3.18.
在 3.16 版本发生变更: Passing an object that is not a string, bytes, or None as
urlstring or scheme now raises TypeError instead of
AttributeError.
自 3.16 版本弃用: Accepting objects with false values (like 0 and []) except empty
strings, byte-like objects and None as urlstring or scheme is
now deprecated. They will raise TypeError in Python 3.18.
用 urlparse() 返回的元组元素组成一个字符串形式的完整 URL。 parts 参数可以是任何包含六个条目的可迭代对象。
This may result in a slightly different, but equivalent URL, if the
URL that was parsed originally had unnecessary delimiters (for example,
a ? with an empty query; the RFC states that these are equivalent).
If keep_empty is true, empty strings are kept in the result (for example,
a ? for an empty query), only None components are omitted.
This allows rebuilding a URL that was parsed with option
missing_as_none=True.
By default, keep_empty is true if parts is the result of the
urlparse() call with missing_as_none=True.
在 3.15 版本发生变更: 增加 keep_empty 形参。
在 3.16 版本发生变更: Passing an object that is not a string, bytes, or None in parts
now raises TypeError instead of AttributeError.
自 3.16 版本弃用: Accepting objects with false values (like 0 and []) except empty
strings, byte-like objects and None in parts is now deprecated.
They will raise TypeError in Python 3.18.
在 3.16 版本发生变更: Passing an object that is not a string, bytes, or None as base or
url now raises TypeError instead of AttributeError.
自 3.16 版本弃用: Accepting objects with false values (like 0 and []) except empty
strings, byte-like objects and None as base or url is now
deprecated. They will raise TypeError in Python 3.18.
If url contains a fragment identifier, return a modified version of url
with no fragment identifier, and the fragment identifier as a separate
string. If there is no fragment identifier in url, return url unmodified
and an empty string (by default) or None if missing_as_none is true.
在 3.16 版本发生变更: Passing an object that is not a string, bytes, or None as url now
raises TypeError instead of AttributeError.
自 3.16 版本弃用: Accepting objects with false values (like 0 and []) except empty
strings, byte-like objects and None as url is now deprecated.
They will raise TypeError in Python 3.18.
Instead of raising an exception on unusual input, they may instead return some
component parts as empty strings or None (depending on the value of the
missing_as_none argument).
Or components may contain more than perhaps they should.
What constitutes a URL is not universally well defined. Different applications
have different needs and desired constraints. For instance the living WHATWG
spec describes what user facing web clients such as a web browser require.
While RFC 3986 is more general. These functions incorporate some aspects of
both, but cannot be claimed compliant with either. The APIs and existing user
code with expectations on specific behaviors predate both standards leading us
to be very cautious about making API behavior changes.
Return the re-combined version of the original URL as a string. This may
differ from the original URL in that the scheme may be normalized to lower
case and empty components may be dropped. Specifically, empty parameters,
queries, and fragment identifiers will be removed unless the URL was parsed
with missing_as_none=True.