python包管理工具
pip
若发现报错,则可以通过 -i 命令指定软件源
requests库安装
通过 pip ,如上
或通过 pycharm
![](https://img-blog.csdnimg.cn/direct/0f04eadf6f5b4ed8a36a471f0605d5da.png)
![](https://img-blog.csdnimg.cn/direct/84b56d4ed0c04628926973a8d5973024.png)
搜索 requests ,并安装即可
![](https://img-blog.csdnimg.cn/direct/4a8ce4fdf480436980409707367a5aca.png)
下载成功的证明
![](https://img-blog.csdnimg.cn/direct/f3f408292b324d67bb674aca3201c8a0.png)
requests库使用
模拟 http
重要参数如下
![](https://img-blog.csdnimg.cn/direct/a182f592c4d240a08d76d94ed9047544.png)
![](https://img-blog.csdnimg.cn/direct/92f7e0a3af5e47938c5247ee9b56429e.png)
如何模拟发包
![](https://img-blog.csdnimg.cn/direct/c159c0a7c9c94922ab4aa18d79c3e98d.png)
支持模拟各种 http method
![](https://img-blog.csdnimg.cn/direct/3dd7ebbd272e47c9b056747f13a743d9.png)
![](https://img-blog.csdnimg.cn/direct/f15cfd0bd0b64a0f8dcd963ce1052781.png)
代理获取数据包
proxy={"http":"127.0.0.1:8080","https":"127.0.0.1:8080"}
r=requests.get(url="http://www.baidu.com",proxies=proxy)
修改请求头
header={"User-Agent":"666"}
r=requests.get(url="http://www.baidu.com",proxies=proxy,headers=header)
模拟 get 请求传参和 post 请求传参
para={'a':'b'}
data={'a':'b'}
r=requests.post(url="http://www.baidu.com",params=para,data=data,proxies=proxy,h
eaders=header)
params为get请求传参
data为post请求传参
模拟 cookie 传参
cookie={'a':'213'}
r=requests.post(url="http://www.baidu.com",cookies=cookie,params=para,data=data,
proxies=proxy,headers=header)
解决 https 报错问题
verify=False #该字段的作用为忽略证书校验