繁体   English   中英

Python XPATH 未将信息正确写入文件

[英]Python XPATH not writing information to file correctly

def removeExcess():
    fileopen = open(file, 'r+')
    doc = etree.XML(fileopen.read())
    write = open('testwrite.nessus', 'a')
    
    for severity in (doc.xpath('//ReportItem')):
        severity2 = (severity.xpath('@severity'))
        if severity2[0] == '0':
            
            severity.getparent().remove(severity)
            print(severity[0].xpath)

        write.seek(0)
        write.write(str(severity[0]))
        write.truncate
    
    print("File Saved to "  + file)
    fileopen.close

上面的代码采用 nessus 文件解析信息并删除任何严重性为 0 的代码,但是在写入文件时我得到

<Element description at 0x10e599280>

而不是实际描述。 有人可以帮我指出正确的方向吗?

谢谢

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM