Skip to content
This repository was archived by the owner on Dec 22, 2023. It is now read-only.

Commit 1c968f0

Browse files
committed
Added webdriver_manager
1 parent b02bf87 commit 1c968f0

File tree

2 files changed

+36
-18
lines changed

2 files changed

+36
-18
lines changed
Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,39 @@
11
# Web Scraping COVID-19 Data for Top 10 Countries Affected (Issue #31)
22
# https://github.com/Python-World/Python_and_the_Web/issues/31
33
# Contributed by @tauseefmohammed2 : https://github.com/tauseefmohammed2
4+
# Updated by @officialpm : https://github.com/officialpm
45

5-
# Requirements :
6+
# Requirements :
67
# Selenium (Web Scrapping Python Library. Install : pip install selenium)
7-
# ChromeDriver (Used for Automated Navigation to URLs, which are Provided by Selenium as Input. Download : https://chromedriver.chromium.org/downloads)
88
# Pandas (Data Manipulation Library. Install : pip install pandas)
99

10-
from selenium import webdriver
11-
import pandas
1210
import datetime
1311

12+
import pandas
13+
from selenium import webdriver
14+
from webdriver_manager.chrome import ChromeDriverManager
15+
1416
td = datetime.date.today()
1517
wait_imp = 10
1618
CO = webdriver.ChromeOptions()
17-
CO.add_experimental_option('useAutomationExtension', False)
18-
CO.add_argument('--ignore-certificate-errors')
19-
CO.add_argument('--headless')
19+
CO.add_experimental_option("useAutomationExtension", False)
20+
CO.add_argument("--ignore-certificate-errors")
21+
CO.add_argument("--headless")
2022

2123
# Creating WebDriver Object
22-
wd = webdriver.Chrome(r'C:\\Users\\TEMP\\Downloads\\chromedriver_win32 (1)\\chromedriver.exe',options=CO)
23-
# Replace the Above Location of chromedriver.exe with your Saved Location
24+
wd = webdriver.Chrome(ChromeDriverManager().install(), options=CO)
25+
# Replace the Above Location of chromedriver.exe with your Saved Location
2426

25-
print ("Date:",td.strftime("%b-%d-%Y"))
26-
print ("--------------------------------------------------------------------------------------------")
27-
print (" COVID-19 Statistics From Around the World (Top 10 Countries) ")
28-
print ("--------------------------------------------------------------------------------------------")
27+
print("Date:", td.strftime("%b-%d-%Y"))
28+
print(
29+
"--------------------------------------------------------------------------------------------"
30+
)
31+
print(
32+
" COVID-19 Statistics From Around the World (Top 10 Countries) "
33+
)
34+
print(
35+
"--------------------------------------------------------------------------------------------"
36+
)
2937

3038
# Using get() method to Open a URL (WHO)
3139
wd.get("https://www.who.int/emergencies/diseases/novel-coronavirus-2019")
@@ -39,15 +47,17 @@
3947
print("-------------------------------------------------------")
4048

4149
# Using get() method to Open a URL (Worldometers)
42-
wd.get("https://www.worldometers.info/coronavirus/countries-where-coronavirus-has-spread/")
50+
wd.get(
51+
"https://www.worldometers.info/coronavirus/countries-where-coronavirus-has-spread/"
52+
)
4353

4454
# Creating Empty Lists to Store Information which will be Retrieved
4555
country_list = []
4656
cases_list = []
4757
deaths_list = []
4858
continent_list = []
4959

50-
table = wd.find_element_by_id("table3")
60+
table = wd.find_element_by_id("table3")
5161
count = 0
5262
for row in table.find_elements_by_xpath(".//tr"):
5363
if count == 0:
@@ -58,7 +68,7 @@
5868
cases_list.append(lst[1])
5969
deaths_list.append(lst[2])
6070
continent_list.append(lst[3])
61-
if count < 11 :
71+
if count < 11:
6272
print("Country : ", lst[0])
6373
print("Total Cases : ", lst[1])
6474
print("Total Deaths : ", lst[2])
@@ -69,6 +79,13 @@
6979
wd.quit()
7080

7181
# Creating a DataFrame (2D-Tabular Data Structure) using the Information Collected
72-
df = pandas.DataFrame(data={"Country": country_list, "Total Cases": cases_list, "Total Deaths": deaths_list, "Continent": continent_list})
82+
df = pandas.DataFrame(
83+
data={
84+
"Country": country_list,
85+
"Total Cases": cases_list,
86+
"Total Deaths": deaths_list,
87+
"Continent": continent_list,
88+
}
89+
)
7390
# Using to_csv() Function which Dumps the Data from the DataFrame to a CSV File
74-
df.to_csv("./data.csv", sep=',',index=False)
91+
df.to_csv("./data.csv", sep=",", index=False)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
selenium==3.141.0
22
pandas==1.0.1
3+
webdriver-manager

0 commit comments

Comments
 (0)