Pythonでurldecodeの使い方プログラム

サンプルコード:

import urllib

def urldecode(query):
d = {}
a = query.split('&’)
for s in a:
if s.find('=’):
k,v = map(urllib.unquote, s.split('=’))
try:
d[k].append(v)
except KeyError:
d[k] = [v]

return d

if __name__ == '__main__’:
str = “""cityinfo=%96k%8AC%93%B9″""
print urldecode(str)[“cityinfo"][0].decode(“utf-8").encode(“shitf-jis")
print urldecode(str)[“button"][0].decode(“utf-8").encode(“shift-jis")

Development

Posted by arkgame