Scraping Covid-19 statistics using BeautifulSoup Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report Coronavirus, one of the biggest pandemic has brought all the world to Danger. Along with this, it is one of the trending News, everyone has this day. In this article, we will be scraping data and printing Covid-19 statistics in human-readable form. The data will be scraped from this websitePrerequisites: The libraries 'requests', 'bs4', and 'texttable' have to be installed - pip install bs4 pip install requests pip install texttable Project : Let's head over to code, create a file called run.py. Python3 # importing modules import requests from bs4 import BeautifulSoup # URL for scraping data url = 'https://www.worldometers.info/coronavirus/countries-where-coronavirus-has-spread/' # get URL html page = requests.get(url) soup = BeautifulSoup(page.text, 'html.parser') data = [] # soup.find_all('td') will scrape every # element in the url's table data_iterator = iter(soup.find_all('td')) # data_iterator is the iterator of the table # This loop will keep repeating till there is # data available in the iterator while True: try: country = next(data_iterator).text confirmed = next(data_iterator).text deaths = next(data_iterator).text continent = next(data_iterator).text # For 'confirmed' and 'deaths', # make sure to remove the commas # and convert to int data.append(( country, int(confirmed.replace(', ', '')), int(deaths.replace(', ', '')), continent )) # StopIteration error is raised when # there are no more elements left to # iterate through except StopIteration: break # Sort the data by the number of confirmed cases data.sort(key = lambda row: row[1], reverse = True) To print the data in human-readable format, we will use the library 'texttable' Python3 # create texttable object import texttable as tt table = tt.Texttable() # Add an empty row at the beginning for the headers table.add_rows([(None, None, None, None)] + data) # 'l' denotes left, 'c' denotes center, # and 'r' denotes right table.set_cols_align(('c', 'c', 'c', 'c')) table.header((' Country ', ' Number of cases ', ' Deaths ', ' Continent ')) print(table.draw()) Output: +---------------------------+-------------------+----------+-------------------+ | Country | Number of cases | Deaths | Continent | +===========================+===================+==========+===================+ | United States | 644348 | 28554 | North America | +---------------------------+-------------------+----------+-------------------+ | Spain | 180659 | 18812 | Europe | +---------------------------+-------------------+----------+-------------------+ | Italy | 165155 | 21645 | Europe | +---------------------------+-------------------+----------+-------------------+ ... NOTE: The output depends on the current statisticsStay home, stay safe! Comment More infoAdvertise with us Next Article Python - Retrieve latest Covid-19 World Data using COVID19Py library S srivathspradeep Follow Improve Article Tags : Python Python Programs Write From Home Python-BS3 Web-scraping Python web-scraping-exercises +2 More Practice Tags : python Similar Reads Python - Retrieve latest Covid-19 World Data using COVID19Py library COVID19Py Library retrieves the latest data revolving around the Covid-19 pandemic. This Covid-19 World Dataset is hosted at the John Hopkins University servers. To install the library, execute below command in your system command line: pip install COVID19Py The library provides the following metho 2 min read How to Scrape Web Data from Google using Python? Prerequisites: Python Requests, Implementing Web Scraping in Python with BeautifulSoup Web scraping is a technique to fetch data from websites. While surfing on the web, many websites donât allow the user to save data for personal use. One way is to manually copy-paste the data, which both tedious a 2 min read How to Scrape Web Data from Google using Python? Prerequisites: Python Requests, Implementing Web Scraping in Python with BeautifulSoup Web scraping is a technique to fetch data from websites. While surfing on the web, many websites donât allow the user to save data for personal use. One way is to manually copy-paste the data, which both tedious a 2 min read How to Scrape Web Data from Google using Python? Prerequisites: Python Requests, Implementing Web Scraping in Python with BeautifulSoup Web scraping is a technique to fetch data from websites. While surfing on the web, many websites donât allow the user to save data for personal use. One way is to manually copy-paste the data, which both tedious a 2 min read How to Scrape Nested Tags using BeautifulSoup? We can scrap the Nested tag in beautiful soup with help of. (dot) operator. After creating a soup of the page if we want to navigate nested tag then with the help of. we can do it. For scraping Nested Tag using Beautifulsoup follow the below-mentioned steps. Step-by-step Approach Step 1: The first s 3 min read Web Scraping using Beautifulsoup and scrapingdog API In this post we are going to scrape dynamic websites that use JavaScript libraries like React.js, Vue.js, Angular.js, etc you have to put extra efforts. It is an easy but lengthy process if you are going to install all the libraries like Selenium, Puppeteer, and headerless browsers like Phantom.js. 5 min read Like