Python2中,可以这样做:
>>> print urllib.unquote("%E6%B5%8B%E8%AF%95abc")
测试abc
但是Python3并没有unquote属性,要达成一样的效果,要怎么做呢?
#python3
import urllib.parseurl编码:
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]
本回答被网友采纳