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))

 

 
 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM