Beautiful soup how print a tag while iterating over it .

Posted by Bunny Rabbit on Stack Overflow See other posts from Stack Overflow or by Bunny Rabbit
Published on 2011-01-01T20:25:15Z Indexed on 2011/01/01 20:53 UTC
Read the original article Hit count: 472

Filed under:
|
|
<?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>....

My xml looks like this , i want to get the locations,

i am trying

from BeautifulSoup import BeautifulSoup as bs soup = bs (the_above_xml_text) for track in soup.tracklist: print track.location.string

but that is not working because i am getting

AttributeError: 'NavigableString' object has no attribute 'location'

how can i achive the result , thanks in advance.

© Stack Overflow or respective owner

Related posts about python

Related posts about Xml