Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想从 url 解析查询部分,这是我的代码:
>>> from urlparse import urlparse, parse_qs >>> url = '/?param1¶m2=2' >>> parse_qs(urlparse(url).query) >>> {'param2': ['23']}
这段代码看起来不错,但“parse_qs”方法会丢失“param1”或“param1=”等查询参数。我可以用标准库解析查询部分并保存所有参数吗?
你要:
from urlparse import parse_qs, urlparse parse_qs(urlparse(url).query, keep_blank_values=True) # {'param2': ['2'], 'param1': ['']}