Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- from bs4 import BeautifulSoup
- page = requests.get("https://www.worldometers.info/coronavirus/#countries")
- soup = BeautifulSoup(page.content, 'html.parser')
- results = soup.find(id='main_table_countries_today')
- count_table = soup.find('table')
- table_rows = count_table.find_all('tr')
- countries = {}
- for tr in table_rows:
- td = tr.find_all('td')
- row = [cell.text.strip() for cell in td]
- res = [val for idx, val in enumerate(row)
- if val or (not val and row[idx-1])]
- if len(res) > 0 :
- countries[res[0]] = res
- countries_data = {}
- for key in countries.keys() :
- if key == "MS Zaandam" :
- print(countries[key])
- countries_data[key] = {
- 'total cases': countries[key][1],
- 'new-cases': countries[key][2],
- 'total deaths': countries[key][3],
- 'new-deaths': countries[key][4],
- 'total-recovered': countries[key][5],
- }
- else :
- countries_data[key] = {
- 'total cases': countries[key][1],
- 'new-cases': countries[key][2],
- 'total deaths': countries[key][3],
- 'new-deaths': countries[key][4],
- 'total-recovered': countries[key][5],
- 'active-cases': countries[key][6],
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement