标题: [问题求助] python解析xml的问题 [打印本页]
作者: netdzb 时间: 2020-9-17 14:30 标题: python解析xml的问题
<trackList>
<track>
<title>01 - Little People.mp3</title>
<location>h1</location>
</track>
<track>
<title>02 - Empty Shell.mp3</title>
<location>h2</location>
</track>
<track>
<title>03 - And Always.mp3</title>
<location>h3</location>
</track>
<track>
<title>04 - Your Hand Letter.mp3</title>
<location>h4</location>
</track>
<track>
<title>05 - Fairway.mp3</title>
<location>h5</location>
</track>
<title>06 - America Ended Song.mp3</title>
<location>h6</location>
<title>01 - Line Up.mp3</title>
<location>h7</location>
<title>02 - Self-Timer.mp3</title>
<location>h8</location>
<title>03 - Save Oneself.mp3</title>
<location>h9</location>
<title>04 - I'm Good Cheat.mp3</title>
<location>h10</location>
<title>05 - Let the Matter Rest.mp3</title>
<location>h11</location>
<title>06 - Self-Timer (Feat. Xiao Fei).mp3</title>
<location>h12</location>
<title>07 - Line Up (Confirmation Edition).mp3</title>
<location>h13</location>
</trackList>
作者: netdzb 时间: 2020-9-17 14:31
回复 1# netdzb
我的代码如下,但是我只能打印显示没有被track包含住的内容。
如果想显示被track包含的内容应该怎么做?
from xml.etree import ElementTree
doc = ElementTree.parse("xml.txt")
for e in doc.findall("title"):
print(e.text)
for f in doc.findall("location"):
print(f.text)
作者: brim 时间: 2020-9-22 15:11
- from xml.etree import ElementTree
- doc = ElementTree.parse("20200922.xml")
- for e in doc.findall("track"):
- for a in e.findall("title"):
- print(a.text)
- for f in e.findall("location"):
- print(f.text)
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |