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)  # 不会报错,最佳方法
    
    
    
  • 相关阅读:
    转:一道笔试题-将int型数组强制转换为char*,再求strlen,涉及大小端
    转:git windows中文 乱码问题解决汇总
    git教程1
    刘汝佳黑书 pku等oj题目
    C/C++ qsort()快速排序用法
    char s[]字串和char *s字串有什麼区别?
    c语言‘’ ,‘0’, “0” ,0之间的区别
    带符号的char类型取值范围为什么是-128——127
    c语言memset详解
    【线性规划与网络流24题】孤岛营救问题 分层图
  • 原文地址:https://www.cnblogs.com/amize/p/13789133.html
Copyright © 2011-2022 走看看