urlparse解析URL参数
python2
#! /usr/bin/env python # -*- coding:utf8 -*- # Author:zhangning import urlparse def url2Dict(query): return dict([(k, urlparse.unquote(v[0])) for k, v in urlparse.parse_qs(query).items()])
python3
在python 3中 urlparse模块被集成到了urllib中,所以用法有点不一样
1 #! /usr/bin/env python 2 # -*- coding:utf8 -*- 3 # Author:zhangning 4 5 from urllib import parse 6 7 8 def url2Dict(query): 9 return dict([(k, parse.unquote(v[0])) for k, v in parse.parse_qs(query).items()])
详细见:https://blog.csdn.net/zly412934578/article/details/77776659