Advertisement
jarekmor

energy_tge

Mar 27th, 2023 (edited)
1,006
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.85 KB | None | 0 0
  1. import requests
  2. from bs4 import BeautifulSoup
  3. import json
  4.  
  5. url = "https://tge.pl/energia-elektryczna-rdn"
  6. r = requests.get(url)
  7.  
  8. soup = BeautifulSoup(r.content, 'lxml')
  9. head = soup.find('table', {'class':"footable table table-hover table-padding"})
  10. table = head.find('tbody')
  11.  
  12. lista = []
  13. for row in table.find_all('tr'):
  14.     li = []
  15.     slown = {}
  16.     for col in row.find_all('td'):
  17.         li.append(col.text.replace('\n','').replace('\t',''))
  18.     slown = {
  19.             'Czas': li[0],
  20.             'FIXING_I' : [{'Kurs (PLN/MWh)': li[1]},{'Wolumen (MWh)': li[2]}],
  21.             'FIXING_II': [{'Kurs (PLN/MWh)': li[3]}, {'Wolumen (MWh)': li[4]}],
  22.             'Notowania_ciagle': [{'Kurs (PLN/MWh)': li[5]},{'Wolumen (MWh)': li[6]}],    
  23.         }
  24.     lista.append(slown)
  25.  
  26. with open("energy.json", "w") as outfile:
  27.     json.dump(lista, outfile)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement