python读取xml文件内容_使用python从xml文件中读取某些信息
我是新手xml,对python有一点经验。我正在尝试使用python的xml.etree.ElementTree模块来解析xml文件。使用print(info.text),它可以打印出所有的元素在xml文件中,例如WIL-RT2,Rtr_Cisco......,但我想只检索WIL-RT2,然后根据WIL-RT2,我可以返回Rtr_Cisco。这是我的xml文件的一部分:<?xml version="1.0" encoding="ISO-8859-1"?>
WIL-RT2
Rtr_Cisco
172.20.111.252
NAT,192.168.249.150
这是我的python代码for item in root.findall("{http://www.ca.com/spectrum/restful/schema/response}model-responses"):
#print(item.findall('{http://www.ca.com/spectrum/restful/schema/response}model'))
for child in item.findall('{http://www.ca.com/spectrum/restful/schema/response}model'):
#print(child.attrib, child.tag)
for info in child.findall('{http://www.ca.com/spectrum/restful/schema/response}attribute'):
print(info.tag, info.attrib)
print(info.text)
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)