Answer the question
In order to leave comments, you need to log in
How to parse xml page?
Hello, I recently started learning python, I set myself the task of writing a currency parser, I managed to parse html from one site, but this is not at all, I need official data, but I can’t parse from here www.cbr.ru/scripts/XML_daily.asp ?date_req=02/03/2002 data. If it's not difficult to show a small piece of code how to parse? At least how to read the full page, otherwise errors constantly appear)
Answer the question
In order to leave comments, you need to log in
As I understand it, you need to get the exchange rate of the Belarusian ruble. This is easy to do using xpath using the lxml library.
import urllib
import lxml.etree as etree
def get_xml(url):
response = urllib.urlopen(url)
return response.read()
if __name__ == '__main__':
xml = get_xml('http://www.cbr.ru/scripts/XML_daily.asp?date_req=02/03/2002')
xml_data = etree.fromstring(xml)
bel_rub = xml_data.xpath("/ValCurs/Valute[@ID='R01090']/Value")[0].text
print(bel_rub)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question