31 lines
745 B
Python
Executable File
31 lines
745 B
Python
Executable File
#!/usr/bin/python3
|
|
# -*- coding: latin-1 -*-
|
|
import requests
|
|
from bs4 import BeautifulSoup as sp
|
|
|
|
url='https://www.worldometers.info/coronavirus/'
|
|
|
|
response = requests.get(url)
|
|
|
|
soup = sp(response.text, "lxml")
|
|
|
|
divs = soup.findAll('div', {'id':'maincounter-wrap'})
|
|
|
|
spans=[]
|
|
|
|
for div in divs:
|
|
spans.append(div.find('span').get_text())
|
|
|
|
for i in range(len(spans)):
|
|
spans[i]=spans[i].replace(',','')
|
|
|
|
total = int(spans[0])
|
|
deaths = int(spans[1])
|
|
recovered = int(spans[2])
|
|
|
|
active = int(total)-int(deaths)-int(recovered)
|
|
|
|
outfile = open("world.txt","w")
|
|
|
|
print('Overall data about the COVID-19 pandemic\n\nTotal cases: {:,}\nActive cases: {:,}\nRecovered people: {:,}\nDeaths: {:,}'.format(total, active, recovered, deaths), file=outfile)
|