Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- from bs4 import BeautifulSoup
- import json
- url = "https://tge.pl/energia-elektryczna-rdn"
- r = requests.get(url)
- soup = BeautifulSoup(r.content, 'lxml')
- head = soup.find('table', {'class':"footable table table-hover table-padding"})
- table = head.find('tbody')
- lista = []
- for row in table.find_all('tr'):
- li = []
- slown = {}
- for col in row.find_all('td'):
- li.append(col.text.replace('\n','').replace('\t',''))
- slown = {
- 'Czas': li[0],
- 'FIXING_I' : [{'Kurs (PLN/MWh)': li[1]},{'Wolumen (MWh)': li[2]}],
- 'FIXING_II': [{'Kurs (PLN/MWh)': li[3]}, {'Wolumen (MWh)': li[4]}],
- 'Notowania_ciagle': [{'Kurs (PLN/MWh)': li[5]},{'Wolumen (MWh)': li[6]}],
- }
- lista.append(slown)
- with open("energy.json", "w") as outfile:
- json.dump(lista, outfile)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement