Last active
April 19, 2020 17:48
-
-
Save JoeThunyathep/8c2a8ba0681c46dc6298cf62e41262bc to your computer and use it in GitHub Desktop.
Scraping COVID-19 Data from Worldometer every 1 minute
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests, datetime | |
from bs4 import BeautifulSoup #To install: pip3 install beautifulsoup4 | |
url = "https://www.worldometers.info/coronavirus/" | |
req = requests.get(url) | |
bsObj = BeautifulSoup(req.text, "html.parser") | |
data = bsObj.find_all("div",class_ = "maincounter-number") | |
NumTotalCase = data[0].text.strip().replace(',', '') | |
NumDeaths = data[1].text.strip().replace(',', '') | |
NumRecovered = data[2].text.strip().replace(',', '') | |
TimeNow = datetime.datetime.now() | |
with open('world_corona_case.csv','a') as fd: | |
fd.write(f"{TimeNow},{NumTotalCase},{NumDeaths},{NumRecovered};") | |
print(f"Successfully store COVID-19 data at {TimeNow}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment