当前位置:   article > 正文

python解析postman导出json文件_python 解析postman报告放入

python 解析postman报告放入

coding:utf-8

import json

with open("postman_collection.json", "r+", encoding="utf-8") as f:
    d = json.loads(f.read())
    result = []
    for items in d["item"]:
        if 'item' in items.keys():
            name = items['name']
            for item in items['item']:
                if 'item' in item.keys():
                    pass
                else:
                    # 接口名称
                    modelName = item['name']
                    # print()
                    # 请求路由
                    path = item['request']['url']['raw']  # model/verifyapi/verifyIdcard
                    # print(path)
                    # 请求方法
                    # method = item['request']['method']  # POST
                    # print(method)
                    # 传参
                    parms = item['request']['body']['raw']  # 取出来的是字符串,想提取body里面的参数需转成字典
                    # parms_dist = ast.literal_eval(parms)  #用ast.literal_eval转换字典执行过程中会报错,故用json.load转字典
                    parms_dist = json.loads(parms)  # 转字典
                    print(modelName, "\t", f"/{name}/{modelName}", "\t", path, "\t", parms_dist)
                    # 产品编号
                    # modelNo = parms_dist["prodId"]
                    # print(modelNo)
                    # print("")
        else:
            # 接口名称
            modelName = items['name']
            # print(modelName)
            # 请求路由
            path = items['request']['url']['raw']  # model/verifyapi/verifyIdcard
            # print(path)
            # 请求方法
            # method = items['request']['method']  # POST
            # print(method)
            # 传参
            parms = items['request']['body']['raw']  # 取出来的是字符串,想提取body里面的参数需转成字典
            # parms_dist = ast.literal_eval(parms)  #用ast.literal_eval转换字典执行过程中会报错,故用json.load转字典
            parms_dist = json.loads(parms)  # 转字典
            print(modelName, "\t", modelName, "\t", path, "\t", parms_dist)
            # 产品编号
            # modelNo = parms_dist["prodId"]
            # print(modelNo)
            # print("")
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/710185
推荐阅读
相关标签
  

闽ICP备14008679号