Hi I have trouble understanding the minidom module for Python.
I have xml that looks like this:
<Show>
<name>Dexter</name>
<totalseasons>7</totalseasons>
<Episodelist>
<Season no="1">
<episode>
<epnum>1</epnum>
<seasonnum>01</seasonnum>
<prodnum>101</prodnum>
<airdate>2006-10-01</airdate>
<link>http://www.tvrage.com/Dexter/episodes/408409</link>
<title>Dexter</title>
</episode>
<episode>
<epnum>2</epnum>
<seasonnum>02</seasonnum>
<prodnum>102</prodnum>
<airdate>2006-10-08</airdate>
<link>http://www.tvrage.com/Dexter/episodes/408410</link>
<title>Crocodile</title>
</episode>
<episode>
<epnum>3</epnum>
<seasonnum>03</seasonnum>
<prodnum>103</prodnum>
<airdate>2006-10-15</airdate>
<link>http://www.tvrage.com/Dexter/episodes/408411</link>
<title>Popping Cherry</title>
</episode>
More pretty: http://services.tvrage.com/feeds/episode_list.php?sid=7926
And this is my python code trying to read from that:
xml = minidom.parse(urlopen("http://services.tvrage.com/feeds/episode_list.php?sid=7926"))
for episode in xml.getElementsByTagName('episode'):
for node in episode.attributes['title']:
print node.data
I can’t get the actual episode data out as I want to get all the data from each episode. I’ve tried different variants but I can’t get it to work. Mostly I get a <DOM Element: asdasd> back. I only care about the data inside each episode.
Thanks for the help
Each
episodeelement has child-elements, including atitleelement. Your code, however, is looking for attributes instead.To get text out of a minidom element, you need a helper function:
And then you can more easily print all the titles: