python3读取多行数据作为入参_【python3-2】读取html报告返回值,作为接口传参调用...

获取读取报告数值

把读取报告结果值作为参数变量,作为参数传给请求接口调用

import urllib

import http.cookiejar

import requests

import json

import sys

from urllib import request

from bs4 import BeautifulSoup

# 读取本地报告html文件

path = 'D:\\ant\\ResultReport\\html\\接口测试报告201902260414.html'

with open(path, 'r',encoding='utf-8') as f:

Soup = BeautifulSoup(f.read(), 'lxml')

titles = Soup.select('html > body > table > .Failure > td')

lists = [] #生成数组

for title in titles:

lists.append(title.text)

#打印对应参数数组的值

print("api_total:",lists[0],",","api_pass_total:",lists[1],",","api_pass_rate:",lists[3],",","excute_time:",lists[7])

url = " http://godeye.hqygou.com/api/receiveAutoTestResultTest"

# postdata =urllib.parse.urlencode({

header = {"Content-Type":"application/json"}

raw={

"api_key": "2b0e740f99f20906a54d04ebe9816d9b",

"api_sign": "sTest123!@#",

"project_id": 10007,

"project_name": "SOA",

"platform": "OTHER",

"level": "Core",

"case_total": 0,

"case_pass_total": 0,

"case_pass_rate": 0,

"api_total": lists[0],

"api_pass_total": lists[1], # 调用返回值作为参数

"api_pass_rate": lists[3], # 调用返回值作为参数

"execute_detail": [{

"case_suit_id": "1",

"case_suit_name": "soa-订单",

"module": "order",

"case_total": "0",

"case_pass_total": "0",

"case_pass_rate": "0",

"api_total": lists[0], # 调用返回值作为参数

"api_pass_total": lists[1], # 调用返回值作为参数

"api_pass_rate": lists[3] # 调用返回值作为参数

}],

"execute_stage": "RegressionTest",

"execute_scene": "BaselineRelease",

"execute_type": "Normal",

"autotest_type": "Interface",

"autotest_source": "Jmeter",

"excute_start_time": "2019-02-6 15:25:04",

"excute_end_time": "2019-02-6 15:25:04",

"excute_time": lists[7], # 调用返回值作为参数

"report_url": "shop",

"test_result": 1,

"execute_result": 1,

"desc": ""

}

# }).encode("utf-8")

data = json.dumps(raw)

data1 = bytes(data,"utf8")

print(data1.decode('unicode_escape')) #转换unicode的中文编码

req = urllib.request.Request(url,data1,header)

# print(urllib.request.urlopen(req).read().decode('utf-8'))

# #自动记住cookie

cj = http.cookiejar.CookieJar()

opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))

r = opener.open(req)

# print(r.read().decode("utf-8")) #打印响应参数带unicode的中文编码

print(r.read().decode('unicode_escape')) #转换unicode的中文编码

执行脚本,返回结果

转换前结果:

执行脚本结果

转换后结果

执行脚本结果

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值