简体   繁体   中英

Extracting table from webpage

I am working on an automation project, and I need the historic exchange rates specifically from this page -- http://bnro.ro/files/xml/nbrfxrates2017.htm , and others just like it for different years.

The problem is BS doesn't seem to work since the table is loaded from an XML file. Selenium is not an option, since we need the program to run in background (unless it is possible for selenium) nor is the Forex module, since the rates are slightly different.

Is it possible to get data from this table or the XML file? Or do I have to ask them for their archives?

As you said, the data is loaded from an XML file. If you check the Network tab in the Developer Tools, you can see that XML file is obtained by sending a request to this site - http://bnro.ro/files/xml/years/nbrfxrates2017.xml

You can use this url to get the data using requests module.

import requests

r = requests.get('http://bnro.ro/files/xml/years/nbrfxrates2017.xml')
print('2017-01-03' in r.text)  # To check whether successful.
# True

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM