解析xml并输出到EXECLE

from openpyxl import Workbook

work_book = Workbook()
worksheet = work_book.active

class Readinfo:
def readinfo(self, message):
file_handle = open("readinfo.txt", 'a', encoding='utf-8')
file_handle.write(message)
file_handle.write('\n')

def readinfo_exe(self, row, column, value):
    print(row, column, value, 11111111111111)
    worksheet.cell(row=row, column=column).value = value
    work_book.save('readinfo.xlsx')

》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》
import xml.dom.minidom as xmldom
import os
from readinfo import Readinfo
readinfo = Readinfo()

def read_xml():
path = os.path.join(os.path.dirname(os.path.abspath(file)), "Xml")
datanames = os.listdir("Xml")
i = 0
for dataname in datanames:
xmlfilepath = os.path.join(path, dataname)
# print(dataname.split('.', 1)[0])
readinfo.readinfo(dataname.split('.', 1)[0])
domobj = xmldom.parse(xmlfilepath)
elementobjs = domobj.getElementsByTagName("HTTPSamplerProxy")
for elementobj in elementobjs:
i += 1
readinfo.readinfo(elementobj.getAttribute("testname"))
readinfo.readinfo_exe(i, 1, i)
readinfo.readinfo_exe(i, 2, dataname.split('.', 1)[0])
readinfo.readinfo_exe(i, 3, elementobj.getAttribute("testname"))

if name == 'main':
read_xml()

posted @ 2020-10-23 15:52  博古冠今  阅读(73)  评论(0)    收藏  举报