I use two functions , first read url and secondary extract data.
This is the code source:
from xml.dom import minidom as dom
import urllib
def fetchPage(url):
a = urllib.urlopen(url)
return ''.join(a.readlines())
def extract(page):
a = dom.parseString(page)
item2 = a.getElementsByTagName('SendingDate')[0].firstChild.wholeText
print "DATA ",item2
item = a.getElementsByTagName('Cube')
for i in item:
if i.hasChildNodes() == True:
e = i.getElementsByTagName('Rate')[10].firstChild.wholeText
d = i.getElementsByTagName('Rate')[26].firstChild.wholeText
print "EURO ",e
print "DOLAR ",d
if __name__=='__main__':
page = fetchPage("http://www.bnro.ro/nbrfxrates.xml")
extract(page)
Result is :
DATA 2011-02-03
EURO 4.2609
DOLAR 3.0921
This is all...