您好,登錄后才能下訂單哦!
1 需求,heeaders 參數需要拼接中文參數param 解決如下
url = 'https://....search?keyword=' + param + '&templateId=&page=1&pageSize=10' headers = { "Accept": "application/json, text/javascript, */*; q=0.01", "Accept-Encoding": "gzip, deflate, br", "Accept-Language": "zh-CN,zh;q=0.9", "Connection": "keep-alive", "Cookie": "Hm_lvt_0076fef7e919d8d7b24383dc8f1c852a=1522398473; Hm_lpvt_0076fef7e919d8d7b24383dc8f1c852a=1522398482", "Referer": "https://...../index.html?index=0&keyword=" + urllib.parse.quote(param), "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36", "X-Requested-With": "XMLHttpRequest" } rsp = requests.get(url, headers=header
from urllib import parse str1 = 'haha哈哈' str2 = parse.quote(str1) #quote()將字符串進行編碼 print(str2) #str2=haha%E5%93%88%E5%93%88 str3 = parse.unquote(str2) #解碼字符串 print(str3) #str3=haha哈哈
以上這篇解決python3 requests headers參數不能有中文的問題就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持億速云。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。