python 汉字GB2312 %url编码

import urllib
#汉字转编码
aa=urllib.parse.quote("郭城峰".encode('gb2312'))#编码是GB2312
print(aa)
aa=urllib.parse.quote("格力塔扇".encode('gb2312'))
print(aa)

aa=urllib.parse.quote("张三")#默认编码是UTF-8
print(aa)
aa=urllib.parse.quote("格力塔扇")
print(aa)
#编码转汉字
ab="%D5%C5%C8%FD"
abb="%B8%F1%C1%A6%CB%FE%C9%C8"
abbb="%E6%A0%BC%E5%8A%9B%E5%A1%94%E6%89%87"
ax=urllib.parse.unquote(ab,encoding='gb2312')
axx=urllib.parse.unquote(abb,encoding='gb2312')
axxx=urllib.parse.unquote(abbb)
print(ax)
print(axx)
print(axxx)

ap="陈".encode('unicode-escape').decode()
app="陈".encode('unicode-escape').decode().replace('\\','%')
print(ap)
print(app)
ap="杨".encode('unicode-escape').decode()
app="杨".encode('unicode-escape').decode().replace('\\','%')
print(ap)
print(app)

am=ap.encode('utf-8').decode('unicode-escape')
print(am)

 

posted @ 2022-11-27 08:54  myrj  阅读(471)  评论(0编辑  收藏  举报