【发布时间】:2011-01-01 20:25:15
【问题描述】:
我的 xml 看起来像这样,我想获取位置。
<?xml version="1.0" encoding="UTF-8"?>
<playlist version="1" xmlns="http://xspf.org/ns/0/">
<trackList>
<track>
<location>file:///home/ashu/Music/Collections/randomPicks/ipod%20on%20sep%2009/Coldplay-Sparks.mp3</location>
<title>Coldplay-Sparks</title>
</track>
<track>
<location>file:///home/ashu/Music/Collections/randomPicks/gud%201s/Coldplay%20Warning%20sign.mp3</location>
<title>Coldplay Warning sign</title>
</track>....
我正在尝试:
from BeautifulSoup import BeautifulSoup as bs
soup = bs (the_above_xml_text)
for track in soup.tracklist:
print track.location.string
但这不起作用,因为我得到:
AttributeError: 'NavigableString' object has no attribute 'location'
我怎样才能达到这个结果,提前谢谢。
【问题讨论】:
-
是的,为了简洁起见,我省略了那部分,你想让我全部展示吗?
-
是的。还要解释“不工作”是什么意思。
标签: python xml beautifulsoup