url编码解码的问题(urlencode/quote)

import urllib.parse


params = {
    "wd":"hello人工智能"
}
# 将字典形式的进行编码
query_str = urllib.parse.urlencode(params)
print(query_str)

st = "hello人工智能"
# 将字符串形式的进行编码
res = urllib.parse.quote(st)
print(res)
st1 = "hello%E4%BA%BA%E5%B7%A5%E6%99%BA%E8%83%BD"
# 将字符串形式的简写解码
res1 = urllib.parse.unquote(st1)
print(res1)

结果为:

 

posted @ 2018-11-17 22:05  L某人  阅读(855)  评论(0编辑  收藏  举报