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