当前位置:网站首页>Requests module (requests)
Requests module (requests)
2022-07-01 06:27:00 【HHYZBC】
requests The module is python Sending request module commonly used in , The function is to send http request , Get response data . It needs to be used before use pip Download .
pip install requestsUse requests
- Use requests send out get request
requests.get('https://www.douban.com/')- Send... With parameters get request
Pass in a dictionary as params Parameters can be
requests.get('https://www.douban.com/',params={'a':'python','b':'100'})Instance requested url Then for :
https://www.douban.com/search?a=python&b=100'- Sending requires incoming HTTP Header Of get request
Pass in a field as headers Parameters can be
requests.get('https://www.douban.com/', headers={'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit'})- send out json Data get request :
Pass in a dictionary as json Parameters can be
params = {'key': 'value'}
requests.post(url, json=params)- Send the file get request
Pass in a dictionary as files Parameters can be , The value of the dictionary is the incoming file , When reading files, you need to use rb Mode binary for reading .
upload_files = {'file': open('report.xls', 'rb')}
requests.post(url, files=upload_files)
- Send with Cookie Of get request
Pass in a dictionary as cookies Parameters can be .
cookies= {'name': 'hhh', 'pwd': 'working'}
requests.get(url, cookies=cookies)- Specify the timeout time get request
Pass in a number as timeout Parameters can be . Be careful timeout The unit of parameter is seconds
requests.get(url, timeout=3)- send out post request
take get() Method changed to post() The method can . How to import a dictionary as data Parameters , To act as post Requested data .
requests.post('https://accounts.douban.com/login', data={'form_email': '[email protected]'}) If you need to use other request methods , Will post() Method can be changed into a response method . Such as put(),delete() etc. , You can use put perhaps delete Method to request data .
Common methods for responding to content
After using the above method , Will return an object , It contains all the response contents . In general use response Receive , Response content . The common attributes of this object are :
- status_code
- Status code
- text
- Response body
- content
- Is also a response body , But whether the response is text or binary content ,
contentAttribute acquisition isbytesobject - You can use this property later decode Method , Decode the data , The default is utf-8
- Is also a response body , But whether the response is text or binary content ,
- encoding
- View encoding format
- json
- obtain json data
- headers
- Get response header
- Cookie
- obtain Cookie
边栏推荐
- 【ManageEngine】如何实现网络自动化运维
- 端口扫描工具对企业有什么帮助?
- C#如何打印输出原版数组
- Mysql 表分区创建方法
- Ant new village is one of the special agricultural products that make Tiantou village in Guankou Town, Xiamen become Tiantou village
- Servlet
- 基金定投是高风险产品吗?
- [ManageEngine Zhuohao] helps Huangshi Aikang hospital realize intelligent batch network equipment configuration management
- B-树系列
- JDBC connection pool
猜你喜欢

How does the port scanning tool help enterprises?

Movable mechanical wall clock

记磁盘扇区损坏导致的Mysql故障排查

C# ManualResetEvent 类的理解

【企业数据安全】升级备份策略 保障企业数据安全

【#Unity Shader#自定义材质面板_第二篇】

【Unity Shader 消融效果_案例分享】
![阿里OSS Postman Invalid according to Policy: Policy Condition failed: [“starts-with“, “$key“, “test/“]](/img/3c/7684b7c594f7871471f89007294703.png)
阿里OSS Postman Invalid according to Policy: Policy Condition failed: [“starts-with“, “$key“, “test/“]

【ManageEngine卓豪 】助力世界顶尖音乐学院--茱莉亚学院,提升终端安全

IT服务管理(ITSM)在高等教育领域的应用
随机推荐
局域网监控软件有哪些功能
idea 好用插件汇总!!!
[ManageEngine] terminal management system helps Huasheng securities' digital transformation
基金定投是高风险产品吗?
libpng12.so. 0: cannot open shared object file: no such file or directory
【自动化运维】自动化运维平台有什么用
HCM Beginner (II) - information type
SQL语句
Excel visualization
【KV260】利用XADC生成芯片温度曲线图
golang panic recover自定义异常处理
ManageEngine卓豪助您符合ISO 20000标准(四)
Restframework-simplejwt rewrite authentication mechanism
Record MySQL troubleshooting caused by disk sector damage
数据库产生死锁了请问一下有没有解决办法
Make: g++: command not found
JDBC database operation
Uniapp tree level selector
Ant new village is one of the special agricultural products that make Tiantou village in Guankou Town, Xiamen become Tiantou village
Although pycharm is marked with red in the run-time search path, it does not affect the execution of the program