requests介绍
- requests是一个很实用的Python HTTP客户端库,编写爬虫和测试服务器响应数据时经常会用到,Requests是Python语言的第三方的库,专门用于发送HTTP请求
Requests响应
- r.status_code 响应状态码
- r.heards 响应头
- r.cookies 响应cookies
- r.text 响应文本
- r. encoding 当前编码
- r. content 以字节形式(二进制)返回
通过聚合数据请求
发送无参数的get请求
Request扩充
-
添加等待时间
requests.get(url,timeout=1) #超过等待时间则报错 -
添加请求头信息
requests.get(url,headers=headers) #设置请求头 -
添加文件
requests.post(url, files=files) #添加文件 -
读取文件中的数据
requests拿到数据请求接口返回状态码
通过断言验证返回状态码和200对比
生成allure的测试报告
dataDemo(存放数据)>> readDemo(读取数据)
useRequests(发送请求)>>testDemo(生成报告)