urlencode编码,解码

urlencode编码,解码,第1张

urlencode编码,解码

字符串传入的字典参数进行urlencode编码,就需要用到两个方法urlencode和quote
urlencode方法传字典参数

from urllib.parse import urlencode, quote, unquote

# urlencode方法参数是字典

body = {
"content": "呃呃呃",
"charsetSelect": "utf-8",
"en": "UrlEncode编码"
}
print(urlencode(body))

quote传字符串参数

# quote方法参数是字符串

print(quote("上海-悠悠"))

url = "http://www.example.com/?a=问问为&b=同人文"
print(quote(url))
======================================================
import requests
from urllib.parse import urlencode, quote, unquote url = "http://www.example.com/"
par = {
"a": "问问",
"b": "嗯嗯"
}
body = {
"content": "嗯嗯",
"charsetSelect": "utf-8",
"en": "UrlEncode编码"
} r = requests.post(url, params=par, data=body)
print(r.url)
print(unquote(r.url))
 
 

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/585803.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-12
下一篇 2022-04-12

发表评论

登录后才能评论

评论列表(0条)

保存