Skip to content

Instantly share code, notes, and snippets.

@i3p9
Last active April 12, 2020 16:21
Show Gist options
  • Save i3p9/6e88b2b503b48754fbdb94a50e648288 to your computer and use it in GitHub Desktop.
Save i3p9/6e88b2b503b48754fbdb94a50e648288 to your computer and use it in GitHub Desktop.
Scraping covid 19 case data from worldmetrics (bangladesh)
import requests
from bs4 import BeautifulSoup
import re
URL = 'https://www.worldometers.info/coronavirus/country/bangladesh' #change the url for other countries
page = requests.get(URL)
soup = BeautifulSoup(page.content, 'html.parser') #makes a soup bs object
results = soup.find(class_='content-inner')
cases =results.find_all('div', class_=('maincounter-number'))
numbers = []
for cases in cases:
total_case = cases.find('span')
total_case_num = total_case.text #gets the element inside the class
numbers.append(total_case_num) #append totalcases, deaths and recovered in order from .text
print("total cases: ", numbers[0], "deaths: ", numbers[1], "recovered: ", numbers[2])
import requests
from bs4 import BeautifulSoup
import re
URL = 'https://www.worldometers.info/coronavirus/country/bangladesh'
page = requests.get(URL)
soup = BeautifulSoup(page.content, 'html.parser')
results = soup.find(id='maincounter-wrap')
cases =results.find_all('div', class_='maincounter-number')
for cases in cases:
total_case = cases.find('span')
total_case_num = total_case.text
print('Total case: ',total_case_num)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment