天天看点

Python URL编解码 encodepython中对URL编码

python中对URL编码

urllib包中parse模块的quote和unquote

from urllib import parse

#这个是js的结果
# encodeURIComponent('中国')
# "%E4%B8%AD%E5%9B%BD"
jsRet='%E4%B8%AD%E5%9B%BD'
print(parse.unquote(jsRet))       #输出:中国
print(jsRet==parse.quote('中国'))  #输出:True           

复制