zoukankan      html  css  js  c++  java
  • python roboot解析 output.xml

    1. 解析html

    2. 解析xml

    import xml.dom.minidom
    
    
    tree = xml.dom.minidom.parse('output.xml')
    robot = tree.documentElement
    root_suite = robot.childNodes
    
    statistics = robot.getElementsByTagName('statistics')
    statistics_suite = statistics[0].getElementsByTagName('suite')
    statistics_suite_stat = statistics_suite[0].getElementsByTagName('stat')
    suite_name = statistics_suite_stat[0].getAttribute('name')
    statistics_suite_pass = statistics_suite_stat[0].getAttribute('pass')
    statistics_suite_fail = statistics_suite_stat[0].getAttribute('fail')
    
    # 打印dom类型的xml
    # pretty_print = lambda f: '
    '.join([line for line in md.parse(open(f)).toprettyxml(indent=' '*2).split('
    ') if line.strip()])
    # 打印str类型的xml ,需要修改pretty_print 函数,只能打印dom 非test对象
    pretty_print = lambda data: '
    '.join([line for line in xml.dom.minidom.parseString(data).toprettyxml(indent=' '*2).split('
    ') if line.strip()])
    
    
    # [<DOM Text node "'
    '">, <DOM Element: suite at 0x99d8928>, ...
    # print(root_suite)
    
    
    #[<DOM Element: statistics at 0x81739b8>]
    # print(statistics)
    
    # 'NodeList' object has no attribute 'toprettyxml'
    # print(statistics.toprettyxml())
    
    
    # for i in statistics:
    #     # print(i.toprettyxml())  # 空格没有去掉
    #     print(pretty_print(i.toprettyxml()))
    
    # 打印指定的dom
    # print(pretty_print(root_suite[5].toprettyxml()))
    
    
    #Test Statistics 数据
    # for i in statistics_suite:
    #     print('*'*100)
    #     print(pretty_print(i.toprettyxml()))
    #
    # for i in statistics_suite:
    #     print('*'*100)
    #     print(pretty_print(i.toprettyxml()))
    #
    # for i in statistics_suite_stat:
    #     print('*'*100)
    #     print(pretty_print(i.toprettyxml()))
    
    
    #pass 的数据
    # for i in statistics_suite_pass:
    #     print('*' * 100)
    #     print(print(i))
    
    # test
    # test=robot.getElementsByTagName('test') # dom list 对象,只有一个
    # print(test)
    # for i in test:
    #     print('*'*100)
    #     print(pretty_print(i.toprettyxml()))
    
    
    # test
    # msgs = robot.getElementsByTagName('msg') # dom list 对象
    # for i in msgs:
    #     # print('*'*100)
    #     # print(pretty_print(i.toprettyxml()))
    #     if i.childNodes[0]:
    #         # print(pretty_print(i.toprettyxml()))
    #         # print(i.childNodes[0])
    #         # print(pretty_print(i.childNodes[0].toprettyxml()))   # 会报错,需要修改pretty_print 函数,只能打印dom 非test对象
    #         # print(i.childNodes[0].toprettyxml())  # 不会报错,不好
    #         print(i.childNodes[0].data)  # 不会报错,最佳方法
    
    
    
  • 相关阅读:
    核心数据类型
    Python入门
    [多校联考2019(Round 4 T2)][51nod 1288]汽油补给(ST表+单调栈)
    [Codeforces 1228E]Another Filling the Grid (排列组合+容斥原理)
    [luogu5339] [TJOI2019]唱、跳、rap和篮球(容斥原理+组合数学)(不用NTT)
    用生成函数推导数列的通项公式
    [Luogu 5465] [LOJ 6435] [PKUSC2018]星际穿越(倍增)
    [BZOJ4569] [Luogu 3295] [SCOI2016]萌萌哒(并查集+倍增)
    [BZOJ4444] [Luogu 4155] [LOJ 2007] [SCOI2015]国旗计划(倍增)
    倍增好题记录
  • 原文地址:https://www.cnblogs.com/amize/p/13789133.html
Copyright © 2011-2022 走看看