日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python etree模块所有函数详解_Python3使用xml.dom.minidom和xml.etree模块儿解析xml文件,封装函数...

發(fā)布時間:2023/12/10 python 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python etree模块所有函数详解_Python3使用xml.dom.minidom和xml.etree模块儿解析xml文件,封装函数... 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

from xml.dom.minidom importparse, parseStringfrom xml.etree importElementTreeimportxml.dom.minidom"""Get XML String info 查詢屬性值

response:xml string

tag:xml tag

element:xml attribute"""

defget_xml_info(response, element):

DOMTree=xml.dom.minidom.parseString(response)returnDOMTree.documentElement.getAttribute(element)"""Get XML String info 查詢制定名稱的特定標(biāo)簽id

xmlstring:xml str

return config id"""

defget_config_id_from_xml(xmlstring, scan):

root=ElementTree.fromstring(xmlstring)

configs= root.findall('config')for config inconfigs:

config_name= config.find('name').textif config_name ==scan:return config.attrib['id']"""Get XML String info 查詢指定id

xmlstring:xml str

return report id"""

defget_report_id_from_xml(xmlstring):

root=ElementTree.fromstring(xmlstring)

report_id= root.find('report_id').textreturnreport_id"""Get XML String info

xmlstring:xml str

return progress"""

defget_progress_from_xml(xmlstring):

root=ElementTree.fromstring(xmlstring)

task= root.find('task')

progress= float(task.find('progress').text)if progress <0:return 100.0

else:returnprogress"""Get XML Report info 從xml文件查詢

file_path : report path"""

defget_xml_report(file_path):

report={}

result_dicts={}

resultsList=[]try:

root=ElementTree.parse(file_path)except:return{}if root is notNone:

creation_time= root.find("creation_time")if creation_time is notNone:

report[creation_time.tag]=creation_time.textif root.find("report") is notNone:

scan_start= root.find("report").find("scan_start")if scan_start is notNone:ifscan_start.text:

report[scan_start.tag]=scan_start.text

results= root.getiterator("result")if results is notNone:for result inresults:if result.find("threat") is notNone:if result.find("threat").text != "Log":

resultsList.append(getResults(result))

report["Results"] =resultsListreturn report

總結(jié)

以上是生活随笔為你收集整理的python etree模块所有函数详解_Python3使用xml.dom.minidom和xml.etree模块儿解析xml文件,封装函数...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。