all Python 3urllib.parsefunction
urllib.parse.parse_qsl()
query string
Parses a query string into a list of (key, value) pairs, keeping the order and repeated keys.
Syntax
urllib.parse.parse_qsl(qs, keep_blank_values=False, strict_parsing=False, encoding='utf-8', errors='replace', max_num_fields=None, separator='&')
Unlike parse_qs() the values are strings, not lists, and the order is kept. dict(parse_qsl(...)) is handy, but with a repeated key it silently keeps the last value. Blank values are dropped unless keep_blank_values=True. The reverse operation is urlencode() of the same list of pairs.
Examples
from urllib.parse import parse_qsl, urlencode
pairs = parse_qsl('a=1&a=2&b=x+y')
print(pairs) # → [('a', '1'), ('a', '2'), ('b', 'x y')]
print(dict(pairs)) # → {'a': '2', 'b': 'x y'} — первое a потеряно
print(urlencode(pairs)) # → a=1&a=2&b=x+y
See also
Open in the full glossarydocs.python.orgReport an inaccuracy