Python-第七周-requests 模块的使用-03

1.概述
在这里插入图片描述
2.requests库的方法
在这里插入图片描述
(1)使用说明
在这里插入图片描述
3.
在这里插入图片描述
实例:
在这里插入图片描述
.
.
.
.
.

.
.
.
.
.
4.requests模块各参数的使用
(1)requests模块各参数的使用
在这里插入图片描述
参数1:

>>> import requests
>>> A = "https://www.baidu.com/"
>>> res = requests.get(A)  #获取网页信息
>>> res.status_code  #判断是否连接成功,200表示成功,400表示失败
200
>>> A = "https://www.zhihu.com/signin?next=%2F"  #知乎网
>>> res = requests.get(A)
>>> res.status_code
400
>>> res.text  #输出页面内容
'<html>\r\n<head><title>400 Bad Request</title></head>\r\n<body bgcolor="white">\r\n<center><h1>400 Bad Request</h1></center>\r\n<hr><center>openresty</center>\r\n</body>\r\n</html>\r\n'
>>> #由上面400 Bad Request可知,出现错误了。这是因为知乎有反爬虫机制。因此,我们需要用 headers 方法来获取。
>>> 

在这里插入图片描述
参数2:
在这里插入图片描述
在这里插入图片描述
参数3:
在这里插入图片描述
参数4:
在这里插入图片描述
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
5.Response对象属性
(1)
在这里插入图片描述
实例1:
在这里插入图片描述
在这里插入图片描述
实例2:
在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Github下载地址:https://github.com/XLAccount/MiaoBo 项目详解地址:http://www.code4app.com/blog-843201-350.html 快速集成RTMP的视频推流教程:http://www.code4app.com/blog-843201-315.html ffmpeg常用命令操作:http://www.code4app.com/blog-843201-326.html #关于IJKMediaFramework/IJKMediaFramework.h找不到的问题,下载后直接拉到项目中即可 下载地址:https://pan.baidu.com/s/1boPOomN 密码::9yd8 #BUG修复: 解决登录程序偶尔崩溃,修复轮播图片和页面控制器叠加等问题,修复新浪授权登录 (2016.9.7) 解决程序运行中偶尔崩溃问题,解决连续下拉刷新崩溃问题,优化代码 (2016.9.8) 优化直播页面,减少不必要的性能消耗,增加用户体验 (2016.9.11) 适配5s以上的机型除了6sPlus和6Plus延迟较大外,其余延迟都较小,网速好的话可以忽略不计 (2016.9.12) 新版本极大优化程序性能,修复关注数据异常等小问题,重新布局热门页面,减少因反复加载带来的性能消耗 (2016.9.13) 增加个人中心页面,采用下拉放大图片 ➕ 波纹效果 (2016.9.14) ![image text](https://github.com/XLAccount/ALLGIFS/blob/master/psb.gif) 展示图片 ![image](https://github.com/XLAccount/ALLGIFS/blob/master/psb-1.gif) 展示图片 ![image text](https://github.com/XLAccount/ALLGIFS/blob/master/psb-2.gif) 展示图片 ![image text](https://github.com/XLAccount/ALLGIFS/blob/master/psb-3.gif) 展示图片 感谢大神Monkey_ALin http://www.jianshu.com/users/9723687edfb5/latest_articles 的demo支持
requests是一个用于发送HTTP请求的Python第三方库,它可以方便地发送HTTP/1.1请求,并且能够自动处理请求和响应的内容。以下是requests模块的基本用法: 1. 安装requests模块 使用pip安装requests模块: ``` pip install requests ``` 2. 发送HTTP请求 使用requests模块发送HTTP请求十分简单,只需要使用requests.get()或requests.post()等方法即可。例如: ``` import requests response = requests.get('http://www.example.com') print(response.status_code) # 打印响应状态码 print(response.text) # 打印响应内容 ``` 3. 带参数的请求 可以使用params参数传递参数。例如: ``` import requests payload = {'key1': 'value1', 'key2': 'value2'} response = requests.get('http://httpbin.org/get', params=payload) print(response.url) # 打印请求的URL ``` 4. 带请求头的请求 可以使用headers参数设置请求头。例如: ``` import requests headers = {'user-agent': 'Mozilla/5.0'} response = requests.get('http://www.example.com', headers=headers) print(response.headers) # 打印响应头 ``` 5. 发送POST请求 使用requests.post()方法发送POST请求。例如: ``` import requests payload = {'key1': 'value1', 'key2': 'value2'} response = requests.post('http://httpbin.org/post', data=payload) print(response.text) # 打印响应内容 ``` 6. 发送文件 使用files参数上传文件。例如: ``` import requests files = {'file': open('example.txt', 'rb')} response = requests.post('http://httpbin.org/post', files=files) print(response.text) # 打印响应内容 ``` 7. 发送Cookie 使用cookies参数发送Cookie。例如: ``` import requests cookies = {'cookies_are': 'working'} response = requests.get('http://httpbin.org/cookies', cookies=cookies) print(response.text) # 打印响应内容 ``` 以上是requests模块的基本用法,更多详细用法可以参考官方文档:https://requests.readthedocs.io/en/master/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AKA小徐

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值