Python convert chinese characters to url

I have a url like

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

this is displayed in the check item. But when it opens in a new tab, it displays as

../work/jobarea.asp C_jobtype =% B8g% C0% E7% BA% DE% b2z% A5D% BA% DE &? Peoplenumber = 151

How to find out what type of encoding is used by the browser to convert it. When I try to do scrapy it shows a different format and stops as 500 internal server errors. Could you please explain to me?

+2


source to share


1 answer


This is Tradtional Chinese, so try 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
經營管理主管

      

+3


source







All Articles