码迷,mamicode.com
首页 > 编程语言 > 详细

python XML模块

时间:2020-06-14 22:11:42      阅读:103      评论:0      收藏:0      [点我收藏+]

标签:test   pytho   imp   ext   遍历   文件   parse   child   python   

import xml.etree.ElementTree as ET

tree = ET.parse("xmltest.xml")#操作的文件
root = tree.getroot()#获取一个内存地址
print(root.tag)#标签名

# 遍历xml文档
for child in root:
print(child.tag, child.attrib)
for i in child:
print(i.tag, i.text,i.attrib)#获取头,内容,属性

# 只遍历year 节点
for node in root.iter(‘year‘):
print(node.tag, node.text)

python XML模块

标签:test   pytho   imp   ext   遍历   文件   parse   child   python   

原文地址:https://www.cnblogs.com/anhao-world/p/13127294.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!