简体   繁体   English

python在URL中转换汉字

[英]python convert chinese characters in url

I have a url like 我有一个网址

href="../job/jobarea.asp?C_jobtype=經營管理主管&peoplenumber=151" , href =“ ../ job / jobarea.asp?C_jobtype =经营管理主管&peoplenumber = 151”

this is shown in inspect element. 这在检查元素中显示。 But when opened in new tab it is showing as 但是在新标签页中打开时,它显示为

../job/jobarea.asp?C_jobtype=%B8g%C0%E7%BA%DE%B2z%A5D%BA%DE&peoplenumber=151 ../job/jobarea.asp?C_jobtype=%B8g%C0%E7%BA%DE%B2z%A5D%BA%DE&peoplenumber=151

How do I know which type of encoding is used by the browser to convert it. 我如何知道浏览器使用哪种编码类型进行转换。 When I try to do scrapy it is showing some other format and it is stopping as 500 internal server error. 当我尝试执行scrapy时,它正在显示其他格式,并且由于500内部服务器错误而停止。 Could you please explain me?? 你能解释一下我吗?

It's Tradtional Chinese, so try cp950 这是繁体中文,请尝试cp950

#-*-coding:utf8 -*-

import urllib
s = '經營管理主管'.decode('utf-8').encode('cp950')
print urllib.quote(s)

q ='%B8g%C0%E7%BA%DE%B2z%A5D%BA%DE'
print urllib.unquote(q).decode('cp950').encode('utf-8')

Result 结果

%B8g%C0%E7%BA%DE%B2z%A5D%BA%DE
經營管理主管

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM