Building a COVID-19 Vaccine Tracker Using Python

Introduction

The COVID-19 pandemic posed unprecedented challenges to communities and economies around the world. As governments and health organizations worked tirelessly to develop vaccines, many technological enthusiasts sought ways to monitor these developments with technology. In this blog post, we’ll dive into a simple or powerful to build a Covid-19 Vaccine Tracker using web scraping techniques. You’ll learn how to use Python libraries like Beautiful Soup and queries to retrieve and modify vaccine data.

This program is perfect for those who want to improve their web scraping skills while working on related real-world problems.

Modules Required

To get started, you need to install a couple of Python libraries that make web scraping easier to build a Covid-19 Vaccine Tracker :

  1. Beautiful Soup (bs4): A Python library for pulling data from HTML and XML files. This module is not built in Python, so you need to:
Python
pip install bs4

2. Requests: You can send HTTP requests in Python with minimal effort. Like Beautiful Soup, this module should be set to:

Python
pip install requests

Project Overview

The process of creating this vaccine monitor involves several steps:

  1. Extract data from the provided URL: We will aim to have a reliable source tracking the progress of the vaccine.
  2. Scrape the Data: Use queries and Beautiful Soup libraries to fetch and analyze HTML content.
  3. Filter and Display Data: Convert filtered data to a format suitable for analysis and display.

Step-by-Step Implementation

Here is a breakdown of the tracker’s implementation:

Step 1: Import the Necessary Libraries

Python
import requests 
from bs4 import BeautifulSoup

Step 2: Create a Function to Fetch Data from the URL

The program takes a URL as input, sends the request, and returns the HTML content.

Python
def getdata(url): 
    r = requests.get(url) 
    return r.text

Step 3: Parse the HTML Content

We pass the URL to the getdata() function and then use Beautiful Soup to parse through the returned HTML data.

Python
htmldata = getdata("https://covid-19tracker.milkeninstitute.org/") 
soup = BeautifulSoup(htmldata, 'html.parser') 
res = soup.find_all("div", class_="is_h5-2 is_developer w-richtext") 
print(str(res))

The output from the code above will be raw data, so you need to format and filter it to extract useful information.

Full Code Example

Here are the complete rules for the COVID-19 vaccine monitor:

Python
import requests 
from bs4 import BeautifulSoup 

def getdata(url): 
    r = requests.get(url) 
    return r.text 
  
htmldata = getdata("https://covid-19tracker.milkeninstitute.org/") 
soup = BeautifulSoup(htmldata, 'html.parser') 
result = str(soup.find_all("div", class_="is_h5-2 is_developer w-richtext")) 
  
print("Vaccine 1: " + result[46:86]) 
print("Vaccine 2: " + result[139:226]) 
print("Vaccine 3: " + result[279:305]) 
print("Vaccine 4: " + result[358:375]) 
print("Vaccine 5: " + result[428:509])

Note: The indexes in the result[] slice are hard-coded and will need to be based on the actual HTML structure of the target web page.

Output

The script will display a list or description of the top vaccines being tracked around the world. Results may vary depending on the website layout and redesign.

Conclusion

This project is a great way to practice your web-scraping skills and also keep up to date with the latest COVID-19 vaccine developments. Combining the power of requests with beautiful soup, you can easily track and edit important information from any website.

If you find this project interesting, try expanding it by adding features such as automatic updates or displaying data in a user-friendly format, such as a GUI or web dashboard

Share This Post:

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top