Take the tour ×  Possible Duplicate: Python, opposite function
urllib.urlencode  I have a url string which is already formatted
with key=value pairs and &'s in between, as created by urllib's
urlencode function. Is there a standard Python library utility
to reverse this process? That is:  Given a string representing a
url, return a string containing the base url and a dictionary
containing the key-value pairs in the url.  I can cook up a
simple solution on my own that does this for reasonable urls,
but I imagine weird things can happen with an arbitrary url. So
is there a standard library function that does this safely?
share|improve this question add comment  marked as duplicate by
Waleed Khan, phihag, unutbu, JeremyKun, Burhan Khalid Oct 28 '12
at 21:19   1 Answer  up vote 4 down vote accepted  The built-in
urlparse does what you want:  >>> bits =
urlparse.urlparse('http://www.example.com/foo?bar=zoo&a=b') >>>
bits.query >>> urlparse.parse_qs(bits.query) {'a': ['b'], 'bar':
['zoo']} share|improve this answ