forked from alienbrains/ISB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Project 7: COVID-19 DataSet Creator
37 lines (29 loc) · 1.1 KB
/
Project 7: COVID-19 DataSet Creator
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from selenium import webdriver
import time
import pandas as pd
import os
#path to your chromedriver
cd='C:\\webdrivers\\chromedriver.exe'
chrome_browser = webdriver.Chrome(cd)
chrome_browser.get("https://www.worldometers.info/coronavirus/")
time.sleep(15)
column_names=['Rank','Country', 'Total Cases', 'New Cases', 'Deaths', 'New Deaths','Recovered', 'Active Cases', 'Critical']
df=pd.DataFrame(columns= column_names)
print(df)
for i in chrome_browser.find_elements_by_xpath('//*[@id="main_table_countries_today"]/tbody/tr'): # tr for each of country
td_list=i.find_elements_by_tag_name('td') # tag name retrieve each piece of info for a country
row=[]
for td in td_list:
row.append(td.text) # creating row ie each country data
data = {}
for j in range(len(df.columns)):
data[df.columns[j]] = row[j]
df = df.append(data, ignore_index=True)
df = df.iloc[1:]
print(df)
base_path='C:\\Users\\Sweta'
path=os.path.join(base_path,'Covid_Dataset_.csv')
#os.mkdir(path)
df.to_csv(path, index = False)
print("The dataset has been saved at the loction: "+path)
chrome_browser.quit()