推荐接口测试脚本

# encoding=utf8 
import xlwt
import urllib.request
from urllib.parse import quote
import json
import time
import string

def json2execl(subject):#将接口查询结果写入execl文件
    title = list(subject[0])
    sheet.write(len(subject)+2,0,url)#在文件尾部写入调用的接口参数
    sheet.write(len(subject)+3,0,date)#在文件尾部写入调用接口的时间
    for i in range(len(title)):
        sheet.write(0,i,title[i])#在文件头部写标题
    for i in range(len(subject)):#逐行读取
        line = list(subject[i].values())#获取list的值
        for j in range(len(line)):#逐列读取
            sheet.write(i+1,j,line[j])#逐行逐列写入文件

date=time.strftime('%Y_%m_%d_%H_%M_%S',time.localtime())
name= '杨幂'
command= 'getmoviesbyname'
#type = 's'
#type = 'v'
#type = 't'
#type = 'c'
mc = '00000001000000100000000000006890'
userid = []
count = 30
excel = xlwt.Workbook(encoding='utf-8')
sheet = excel.add_sheet('xlwt_sheet1')
url = "http://xxx.xxx.xxx.240:8082/idp/"+command+"?name="+name+"&count="+str(count)
url = quote(url,safe=string.printable)#处理包含中文的url
response=urllib.request.urlopen(url)
req=response.read()
req_s = str(req, encoding='utf-8')
req_j=json.loads(req_s)
subject = req_j['subject']

json2execl(subject)

file = command+"_"+name+"_"+str(count)+"_"+date+".xls"
excel.save(file)#保存文件
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值