Reputation: 272134
Given a URl, how can I get a dictionary of parameters back?
Upvotes: 3
Views: 1903
Reputation: 56941
ofcourse, it is called urlparse. However, instead of a dictionary, the urlsplit and urlparse methods output a namedtuple object, which you are easily reference by member attributes. If dictionary is a must, you can construct one using those named tuple values too.
And if you want to parse the query params, use parse_qs
and parse_qsl
from the same module
Upvotes: 2
Reputation: 1032
http://docs.python.org/library/urlparse.html
edit: It returns a tuple of the url parameters. If you absolutely need to have it be in a dictionnary looks like you will have to implement it yourself. (get the tuple then assign it to dict)
string = "addressing scheme network location path query fragment_identifier".split()
url = urlparse.urlsplit("url")
dictionary = dict(zip(string,url))
Not sure if that dictionary line is valid, but it's something like that.
Upvotes: 7