解决python3 requests headers参数不能有中文的问题
作者:RAPIER512 时间:2021-11-04 21:18:42
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哈哈
来源:https://blog.csdn.net/RAPIER512/article/details/79761593
标签:python3,requests,headers
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
浅谈Python描述数据结构之KMP篇
2022-06-09 19:36:23
![](https://img.aspxhome.com/file/2023/9/66869_0s.jpg)
使用Pytorch训练two-head网络的操作
2023-04-06 14:15:59
"模板化"——限制还是激发
2009-03-26 11:36:00
python进阶教程之词典、字典、dict
2022-10-10 10:41:36
如何从ASP连接到Oracle Server?
2009-11-15 19:52:00
Javascript的一种模块模式
2007-12-05 14:04:00
js控制表单不能输入空格的小例子
2013-07-21 11:58:51
python 下载文件的几种方式分享
2021-03-27 14:08:17
Python实现Pig Latin小游戏实例代码
2022-06-27 04:15:36
PJBlog3优化——301定向跳转解决重复内容的问题
2009-05-20 10:40:00
Anaconda下配置python+opencv+contribx的实例讲解
2021-04-10 21:28:33
![](https://img.aspxhome.com/file/2023/6/100276_0s.jpg)
Python实现备份文件实例
2022-01-03 11:10:05
Window.ShowModalDialog使用手册
2008-02-24 14:42:00
提高CSS代码的可读性
2008-05-11 18:59:00
layer弹窗插件操作方法详解
2023-08-09 14:30:14
详解Python如何制作自动发送微信的程序
2021-06-04 13:24:53
![](https://img.aspxhome.com/file/2023/8/99558_0s.png)
python中的hashlib和base64加密模块使用实例
2022-10-19 05:08:23
Yahoo!网站性能最佳体验的34条黄金守则——JavaScript和CSS
2008-05-29 13:34:00
HTML5 Web Storage全解析
2010-06-26 13:06:00
![](https://img.aspxhome.com/file/UploadPic/20106/26/01-15s.jpg)
Pygame 精准检测图像碰撞的问题
2022-01-17 17:56:13