url解码与编码-备用

from urllib import parse
from urllib import request

dict = {'k1': 'v1', 'k2': 'v2', 'k3': 'v3'}
data = parse.urlencode(dict) # 将字典{'k1': 'v1', 'k2': 'v2', 'k3': 'v3'}转换为 k1=v1&k2=v2&k3=v3
print(data, '\n')

str = 'cookie':'deepfos_users=%7B%22color%22%3A%223%22%2C%22email%22%3A%22mengmeng.huang%40proinnova.com.cn%22%2C%22invitationActivation%22%3Atrue%2C%22token%22%3A%22394B24251377B0577E64D0C244E076E3C46EA2AF365408C69DAC5FE791843177%22%2C%22tokenKey%22%3A%22deepfos_token%22%2C%22type%22%3A1%2C%22userId%22%3A%22616ccc37-2ba3-4a8d-9259-8aa99f74230c%22%2C%22username%22%3A%22mengmeng%22%7D; deepfos_token=394B24251377B0577E64D0C244E076E3C46EA2AF365408C69DAC5FE791843177',

str2 = parse.unquote(str) # 解码字符串
print(str2)
str3 = parse.quote(str2) # 对字符串进行编码
print(str3)

posted on 2023-05-09 16:44  多一点  阅读(35)  评论(0编辑  收藏  举报

导航