url.parse相当于Python2.7

时间:2018-06-01 07:36:52

标签: python-3.x python-2.7 url urllib url-parsing

什么是Python2.7等同于

from urllib.parse import urlparse, parse_qs
parsed_url = urlparse(url)
params = parse_qs(parsed_url.query)

我得到了

>>> from urllib.parse import urlparse
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named parse

谢谢!

1 个答案:

答案 0 :(得分:1)

python2 中使用

from urlparse import urlparse, parse_qs
parsed_url = urlparse(url)
params = parse_qs(parsed_url.query)