首页 > 其他 > 详细

xml模块

时间:2018-08-13 21:18:35      阅读:156      评论:0      收藏:0      [点我收藏+]
import xml.etree.ElementTree as et
tree = et.parse(‘a.xml‘)
root = tree.getroot()

print(root)


#三种查找节点的方式
#(1)查找节点的方式 root.iter(‘year‘)
res = root.iter(‘year‘)
# print(res)

# for i in res:
# print(i.tag) #标签名
# print(i.attrib) #标签属性
# print(i.text) #标签文本


#(2) 只能在当前节点的下一节找 find 默认是第一个
# res = root.find(‘country‘)
# print(res.tag)
# print(res.attrib)
# print(res.text)

# res1 = res.find(‘year‘)

# print(res1.tag)
# print(res1.attrib)
# print(res1.text)


#(3)只能在当前节点的下一节找 findall 所有的
# res = root.findall(‘country‘)
# for i in res:
# for item in i:
# print(item.tag)
# print(item.attrib)
# print(item.text)

xml模块

原文:https://www.cnblogs.com/liu--huan/p/9470927.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!