Python Glossary Русский

all Python 3urllib.parseterm

urllib.parse.SplitResult

parse results

The result of urlsplit(): a named tuple of five fields — scheme, netloc, path, query, fragment — plus hostname, port, username and password.

Syntax

SplitResult(scheme, netloc, path, query, fragment)

Unlike ParseResult it has no params: ';…' stays inside path, so unpacking into six variables fails. A missing part is an empty string, not None, and geturl() drops an empty '?' or '#': urlsplit('http://h/p?').geturl() gives 'http://h/p'. It is a tuple: unpacking and indexing work, but fields cannot be assigned — _replace() returns a new object and geturl() turns it back into a string.

Examples

from urllib.parse import urlsplit
r = urlsplit('https://user:pw@Example.COM:8080/x?y=1')
print(r.username, r.hostname, r.port)  # → user example.com 8080
print(r._replace(query='y=2').geturl())  # → https://user:pw@Example.COM:8080/x?y=2
print(urlsplit('http://h/p?').geturl())  # → http://h/p

See also

Open in the full glossarydocs.python.orgReport an inaccuracy