python 接口测试中怎么下载excel并保存在excel


背景:最近在写接口测试用例的时候,需要下载excel,并统计excel里面的数据

1.F12抓取到需要先调用一个接口2002001,该接口返回了一个url,

2.再用get请求这个url,但是返回没有任何东西,需要我们写入excel里

3.写入excel

  def write_excel(sel,msg):
        f=open("oneTable.xls",'wb+')
        f.write(msg)
        f.close()
def export_one_point_zero_table(self,city,supplier,begintime):
self.header["city"]=city
self.header["supplier"] = supplier
self.header["Authorization"]="Bearer "+str(self.login_msp())#构造header
data={"beginTime": begintime}#构造body
reponse=requests.get( self.one_table_url,params=data,headers=self.header)#调2002001接口
print(reponse.text)
one_table_url=json.loads(reponse.text)["data"]["url"]#获取url
reponse1=requests.get(one_table_url,headers={"Accept":"text/html,application/xhtml+xml,application/xml","Upgrade-Insecure-Requests":"1"})#get请求url
self.write_excel(reponse1.content)#写入excel
 
 
export_one_point_zero_table方法就是为了下载excel并写入,且成功下载,在这个文件的同目录下面会生成一个oneTable.xls表


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM