介绍:
requests
是一个很实用的
Python HTTP
客户端库,编写爬虫和测试服务器响应数据时经常会用到,
Requests
是
Python
语言的第三方的库,专门用于发送
HTTP
请求
get
的请求:
![](https://img-blog.csdnimg.cn/2c7a196b4fe04c73a2a89c6728a5d0d1.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAQ2hhb3NpbXU5OTk=,size_20,color_FFFFFF,t_70,g_se,x_16)
import
requests
class
UseRequestClass
():
#get
传参的第一种方式
def
XWTTMethod
(
self
):
r
=
requests
.
get
(
"http://v.juhe.cn/toutiao/index?
type=guonei&key=4b72107de3a197b3bafd9adacf685790"
)
print
(
r
.
text
)
#get
传参的第二种方式
def
XWTTMethod
(
self
):
params
= {
"type"
:
"guonei"
,
"key"
:
"4b72107de3a197b3bafd9adacf685790"
}
r
=
requests
.
g
post
请求
![](https://img-blog.csdnimg.cn/ee974545df1942ec8c59854490a90655.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAQ2hhb3NpbXU5OTk=,size_20,color_FFFFFF,t_70,g_se,x_16)
import
requests
class
UseRequestClass
():
def
XWTTPostMethod
(
self
):
params
= {
"type"
:
"guonei"
,
"key"
:
"4b72107de3a197b3bafd9adacf685790"
}
r
=
requests
.
post
(
"http://v.juhe.cn/toutiao/index"
,
params
=
params
)
#print(r.status_code)
return
r
.
status_code
模块总览:
![](https://img-blog.csdnimg.cn/122d72d75afe4da49f89fc635ab96305.png)
多接口关联:
![](https://img-blog.csdnimg.cn/2a9111ac2cd947578a32d0e300c8597a.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAQ2hhb3NpbXU5OTk=,size_20,color_FFFFFF,t_70,g_se,x_16)
unittest生成测试报告:
pytest生成测试报告:
读取
csv
文件流程 :
存储数据(csv) :
另存为:
读取数据(readDemo) :
测试用例+生成测试报告
读取excle文件流程:
存储数据(xlsx) :
读取数据(readDemo) :
测试用例+生成测试报告: