Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # radiation data from stations in Poland based on https://mapa.paa.gov.pl/
- from requests_html import HTMLSession
- session = HTMLSession()
- import json
- # get session and render html site
- r = session.get('https://mapa.paa.gov.pl/')
- r.html.render(sleep=1, keep_page=True, scrolldown=1)
- # find all CSS 'div' Selectors
- results = r.html.find('div')
- # list of attributes for all CSS Selectors
- list_attrs = []
- for item in results:
- list_attrs.append(item.attrs)
- # list of dictionares with keys and values for "miasto", "wartosc" and 'status of radiation stations
- radiation_list = []
- for item in list_attrs:
- if "('station',)" in str(item):
- radiation_dict = {
- 'miasto': item['data-nazwa'],
- 'wartosc': "{:.3f}".format(float(item['data-wartosc']) / 1000),
- 'status': item['data-status'],
- }
- radiation_list.append(radiation_dict)
- # load data to json format
- jsonString = json.dumps(radiation_list, ensure_ascii=False, sort_keys=True)
- print(jsonString)
- # write data to file
- with open('promieniowanie.json', 'w') as f:
- json.dump(radiation_list, f, ensure_ascii=False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement