Saturday, 27 September 2014

I want to be able to chose which nodes to be printed when importing an XML document to Python



I am using python to display information from a XML file hosted on a website. The code I am using is bellow:



#IMPORTS
from xml.dom import minidom
import urllib

#IMPORTING XML FILE
xmldocurl = 'http://ift.tt/1qHOXoI'
settings = urllib.urlopen(xmldocurl).read()
final = minidom.parseString(settings)

date = final.getElementsByTagName('date')


for node in date:
test = node.getAttribute('timestamp')
print test


This returns the following:



1411853400
1411850700
1411847100
1411843500
1411839000
1411837200
1411831800
1411828200
1411822800
1411820100


I only want it to return the timestamp for the first node under the heading recent matches. This code at the moment returns everything called timestamp but I only want a specific one.


How can I chose this.


Thanks


No comments:

Post a Comment