Python COVID-19 Live Data Scraper














































Python COVID-19 Live Data Scraper



Python COVID-19 Live Data Scraper
Python COVID-19 Live Data Scraper will scrap all india covid-19 data of different states.this project use to web scrap data from (https://www.mygov.in/covid-19) site using Beautiful Soap and data is cleaned and pre-processed Using Pandas. All India covid-19 data is scraped of different states including total number of (active cases, discharged, vaccination, deaths, confirmed) then data is preprocessed & converted into data Frame.
  
import requests
import bs4
import pandas as pd
from time import sleep

url = 'https://www.mygov.in/covid-19'

def covid(url):
    
    covid_data = {
        'State' : [],
        'Confirmed' :[],
        'Active' : [],
        'Discharged' : [],
        'Deaths' : [],
        'Vaccination' : []
    }
    
    
    response = requests.get(url) 
    soup = bs4.BeautifulSoup(response.content,'html5')
    
    if response.status_code == 200:
        divs = soup.find_all('div',attrs={'class': 'views-row'})
        
        for div in divs:
            try :
                state = div.find('span',attrs={'class':'st_name'}).text.strip()
                confirmed = div.find('div',attrs={'class':'tick-confirmed'}).small.text.strip()
                active = div.find('div',attrs={'class':'tick-active'}).small.text.strip()
                discharged = div.find('div',attrs={'class':'tick-discharged'}).small.text.strip()
                deaths = div.find('div',attrs={'class':'tick-death'}).small.text.strip()
                vaccination = div.find('div',attrs={'class':'tick-total-vaccine'}).small.text.strip()

        
                covid_data['State'].append(state)
                covid_data['Confirmed'].append(confirmed)
                covid_data['Active'].append(active)
                covid_data['Discharged'].append(discharged)
                covid_data['Deaths'].append(deaths)
                covid_data['Vaccination'].append(vaccination)
            except:
                break
        covid_data = pd.DataFrame(covid_data)
        return covid_data
    
    else:
        print("ERROR!! Status Code : ",response.status_code,'Reason: ',response.reason)

while True:
    display(covid(url))
    sleep(0.5)

OUTPUT - 


More Articles of ishita jaiswal:

Name Views Likes
Python COVID-19 Live Data Scraper 226 0
Python Cricket Game 1295 0

Comments