Reputation: 403
I need scrape table of historical exchange rates from 01.01.2016 from my local bank web site. I need rates for USD, PLN, HUF, EUR, CZK in pandas dataframe (table) with date.
My code:
from bs4 import BeautifulSoup
import requests
page = requests.get("https://www.tatrabanka.sk/sk/personal/kurzovy-listok/01.01.2016-00:00")
print(page.status_code)
soup = BeautifulSoup(page.content, 'html.parser')
table = soup.find(lambda tag: tag.name=='table')
print(table)
But output table is empty, can you help pls? Thanks.
Upvotes: 1
Views: 103
Reputation: 195543
The data is loaded from external URL. You can use pd.read_json()
to load it into the dataframe:
import pandas as pd
json_url = "https://www.tatrabanka.sk/rest/tatra/exchange/list/01.01.2016-00:00"
skratky = ["USD", "PLN", "HUF", "EUR", "CZK"]
df = pd.read_json(json_url)
print(df.loc[df["feCycd"].isin(skratky)])
Prints:
id feDate feCntr feCycd feAmnt feDnrt feDprt feDsrt feVnrt feVprt feVsrt feLccy rateListId status formattedDate translatedCountry translatedCode flag
1 23253 1451862000000 Česká republika CZK 1 27.3730 26.6710 27.0220 27.8330 26.2110 27.0220 EUR 5764 0 04.01.2016 00:00 Česká republika CZK /templates/tatrabanka/assets/img/flags/cz.svg
7 23249 1451862000000 Maďarsko HUF 1 319.7100 311.5100 315.6100 328.0800 303.1400 315.6100 EUR 5764 1 04.01.2016 00:00 Maďarsko HUF /templates/tatrabanka/assets/img/flags/hu.svg
9 23246 1451862000000 Poľsko PLN 1 4.3210 4.2100 4.2655 4.4340 4.0970 4.2655 EUR 5764 1 04.01.2016 00:00 Poľsko PLN /templates/tatrabanka/assets/img/flags/pl.svg
15 23241 1451862000000 USA USD 1 1.1027 1.0689 1.0885 1.1212 1.0558 1.0885 EUR 5764 0 04.01.2016 00:00 USA USD /templates/tatrabanka/assets/img/flags/us.svg
Upvotes: 2