我正在尝试从xml文件导出所有电影标题,但似乎无法获取标题。xml看起来像:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<videodb>
<version>1</version>
<movie>
<title>2 Guns</title>
<originaltitle>2 Guns</originaltitle>
<ratings>
<rating name="themoviedb" max="10" default="true">
<value>6.500000</value>
<votes>1776</votes>
</rating>
</ratings>
我已经看到了很多xml有value="title"
的值的示例,但是找不到一个在没有value="title"
时有效的指导示例
到目前为止,我的代码是:
#Import required library
import xml.etree.cElementTree as ET
root = ET.parse('D:\\temp\\videodb.xml').getroot()
for type_text in root.findall('movie/title'):
value = type_text.get ('text')
print(value)
XML文件:
代码:
输出:
尝试替换:
与
xml.etree
使用^{您正在查找元素文本;见Element.text
例如,考虑到这种人为设计的XML:
.get('some_attribute')
将返回Some Attribute
,而.text
将返回Some Text
相关问题 更多 >
编程相关推荐