# 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)#保存文件
推荐接口测试脚本
最新推荐文章于 2024-07-19 10:12:47 发布