request请求模拟导出文件(下载文件)

ui界面:

实现代码:

def export(self,host):
'''导出课时券记录'''
#测试接口
  url='https://'+host+r'/ticket-record/export?timespan=1568010189362'
  #请求头
  heard=self.public()
  #发送请求
  r=self.codemao.request2.get(url,headers=heard)
  # 输出请求时长
  print '请求时长:',r.elapsed.total_seconds()
  print r.content
  fp = open("yoyo.xls", "wb")
  fp.write(r.content)
  fp.close()

参考:https://www.cnblogs.com/guo2733/p/10542736.html

原文地址:https://www.cnblogs.com/kaibindirver/p/11497204.html