python转换url中的中文字符 [英] python convert chinese characters in url

查看:48
本文介绍了python转换url中的中文字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像

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

我如何知道浏览器使用哪种类型的编码来转换它.当我尝试做scrapy时,它显示了一些其他格式,并且由于500内部服务器错误而停止.你能解释一下吗??

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. Could you please explain me??

推荐答案

是繁体中文,试试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')

结果

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

这篇关于python转换url中的中文字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆