Does Python 2.6 have a built in URL parameters parser?
Given a URl, how can I get a dictionary of pa开发者_StackOverflow社区rameters back?
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.
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
精彩评论