美文网首页
【python3-2】读取html报告返回值,作为接口传参调用

【python3-2】读取html报告返回值,作为接口传参调用

作者: _王子_ | 来源:发表于2019-03-02 15:23 被阅读0次

获取读取报告数值

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

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的中文编码

执行脚本,返回结果
转换前结果:


执行脚本结果

转换后结果


执行脚本结果

相关文章

  • 【python3-2】读取html报告返回值,作为接口传参调用

    获取读取报告数值 把读取报告结果值作为参数变量,作为参数传给请求接口调用 执行脚本,返回结果转换前结果: 转换后结果

  • 【python3-4】Jenkins pipline集成参数自动

    背景简述 结合前面三篇文章【python3-1】读取jmeter报告内容【python3-2】读取html报告返回...

  • iOS OC Runtime动态调用方法

    调用无参方法 有参有返回值方法

  • iOS WKWebView的使用

    给HTML添加JS代码 进度监听 获取HTML标签值 左滑返回 OC调用JS方法传参/返回值 传递单个字符串: 注...

  • JavaScript函数式编程-高阶函数reduce(三)

    概述对数组中的所有元素调用指定的回调函数。该回调函数的返回值为累积结果,并且此返回值在下一次调用该回调函数时作为参...

  • 函数

    1.无参无返回值 2.无参有返回值 3.有参无返回值 4.有参有返回值 5.调用的更多做法 6.传多个值 7.多类...

  • undefined的四种情景

    变量没有初始化; 读取的对象属性或数组元素不存在; 调用没有明确返回值的函数; 函数的形参没有提供对应实参值。

  • swift闭包传递分析, 闭包声明

    闭包作为参数 有参无返回值 当一个调用者A调用函数loadData. 流程分析: 1.loadData需要一个带有...

  • C语言(四)函数

    函数: 1、函数的定义 2、形参、实参 3、函数的公式 4、无参无返回值 函数函数的调用 5、无参有返回值 函数函...

  • 函数和返回值

    1.定义和调用一个无参无返回值的函数 2.定义和调用一个无参有返回值的函数(返回值类型为int) 3.同一个函数可...

网友评论

      本文标题:【python3-2】读取html报告返回值,作为接口传参调用

      本文链接:https://www.haomeiwen.com/subject/uedeuqtx.html