Python parse XML

来源:互联网 发布:js模糊搜索插件 编辑:程序博客网 时间:2024/04/29 19:08

解析xml 使用下列 library

import xml.etree.ElementTree as ET
tree = ET.parse( ‘xxx.xml’ )

找到所有特定的 tag

for ind, obj in enumerate( tree.iter(tag=’object’) ):
pass

找特定的 tag 和及其 attribute

#obj 是其中一个子结构
a = obj.find(‘bndbox’).find(‘xmax’).text

上面代码找到如下子结构中的数字

<obj>    <bndbox>            <xmax> 352 </xmax>    </bndbox></obj>
0 0
原创粉丝点击