Last active
September 10, 2015 03:08
-
-
Save hondajojo/8658ee72cd7499d54e25 to your computer and use it in GitHub Desktop.
handle non-standard implementations && handle url encode decode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding:utf-8 -*- | |
from urllib import unquote | |
def unquote_u(source): | |
result = unquote(source) | |
print result | |
if '%u' in result: | |
result = result.replace('%u','\\u').decode('unicode_escape') | |
return result | |
print unquote_u('%u957f%u6c99%u5e02%u5de5%u5546%u5c40%u5bbf%u820d') | |
x = '长沙市工商局宿舍' | |
print ''.join('%u'+i.encode('unicode_escape')[2:] for i in unicode(x,'utf-8')) | |
# fang.com的小区搜索url的解码及编码 | |
city = '广州' | |
city_1 = city.decode('utf8').encode('gbk') | |
print quote(city_1) # %B9%E3%D6%DD | |
ccity = u'广州' | |
ccity_1 = ccity.encode('gbk') | |
print quote(ccity_1) # %B9%E3%D6%DD | |
# 解码 | |
e= urllib.unquote('%B9%E3%D6%DD').decode('gbk').encode('utf8') | |
print e |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment