Python3 如何对url解码?实现Python2中urllib.unquote的作用?

Python2中,可以这样做:
>>> print urllib.unquote("%E6%B5%8B%E8%AF%95abc")
测试abc

但是Python3并没有unquote属性,要达成一样的效果,要怎么做呢?

#python3

import urllib.parse
print(urllib.parse.unquote("%E6%B5%8B%E8%AF%95abc"))

温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-03-31

url编码:

import urllib

url = 'http://test.com/s?wd=哈哈'   #如果此网站编码是gbk的话,需要进行解码,从gbk解码成unicode,再从Unicode编码编码为utf-8格式。

url = url.decode('gbk', 'replace')

print urllib.quote(url.encode('utf-8', 'replace'))

参考资料

Python3 如何对url解码?.CSDN博客[引用时间2018-1-1]

本回答被网友采纳
相似回答