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

fixed errors in script, removed references to recovered fields, and a… #649

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 16 additions & 21 deletions Scripts/Web_Scrappers/COVID-19_Stats/COVID-19_scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ def statsFind():
source = requests.get(url, headers=header)
soup = BeautifulSoup(source.content, "lxml")
for i in range(1, 4, 1):
nameFound = soup.select_one(
"#b_context > li:nth-child(1) > div > div.b_tophbb.bgtopgr.bgbtopnone > div > div.covid-modList > div:nth-child({}) > div.cov_modHead > div:nth-child(1)".format(
i
)
).text
if nameFound == "Global cases":
break
try:
print(url)
nameFound = soup.select_one(
"#b_context > li:nth-child(1) > div > div.b_tophbb.bgtopgr.bgbtopnone > div > div.covid-modList > div:nth-child({}) > div.cov_modHead > div:nth-child(1)".format(
i
)
).text
if nameFound == "Global cases":
break
except:
continue
update = soup.select_one(
"div:nth-child({}) > div.cov_modHead > div:nth-child(2)".format(i)
).text
Expand All @@ -40,20 +44,14 @@ def statsFind():
i
)
).text
ttlRecovered = soup.select_one(
"div:nth-child({}) > div:nth-child(2) > div > div.cov_cases > div:nth-child(3) > div.c_row > div:nth-child(1)".format(
i
)
).text
table = [
["Country/State", " : ", name.upper(), " ({})".format(update)],
["Total Cases", " : ", ttlCase],
["Total Deaths", " : ", ttlDeaths],
["Recovered", " : ", ttlRecovered],
[],
[],
]
print(makeTable(table, [], "plain"))
print(makeTable(table, [], "plain"))
print("Enter 0 to terminate")
statsFind()
except:
Expand All @@ -69,14 +67,12 @@ def statsFind():
source = requests.get(url, headers=header)
soup = BeautifulSoup(source.content, "lxml")

ttlCase = soup.select_one("tr.sorttop > th:nth-child(3)").text
ttlDeaths = soup.select_one("tr.sorttop > th:nth-child(4)").text
ttlRecovered = soup.select_one("tr.sorttop > th:nth-child(5)").text
ttlCase = soup.select_one("tr.sorttop > td:nth-child(3)").text
ttlDeaths = soup.select_one("tr.sorttop > td:nth-child(4)").text

table = [
["Total cases", " : ", ttlCase],
["Total deaths", " : ", ttlDeaths],
["Total people recovered", " : ", ttlRecovered],
]

print(
Expand All @@ -87,13 +83,12 @@ def statsFind():

print(" Top 10 countries suffering form COVID-19")
top10 = []
header = ["Rank", "Country\nName", "Total\nCases", "Total\nDeaths", "Total\nRecovered"]
header = ["Rank", "Country\nName", "Total\nCases", "Total\nDeaths"]
for i in range(3, 13, 1):
country = soup.select_one(" tr:nth-child({}) > th:nth-child(2) > a".format(i)).text
ttlCase = soup.select_one("tr:nth-child({}) > td:nth-child(3)".format(i)).text
ttlDeaths = soup.select_one("tr:nth-child({}) > td:nth-child(4)".format(i)).text
ttlRecovered = soup.select_one(" tr:nth-child({}) > td:nth-child(5)".format(i)).text
top10.append([i - 2, country, ttlCase, ttlDeaths, ttlRecovered])
top10.append([i - 2, country, ttlCase, ttlDeaths])

print(makeTable(top10, header, "grid"))

Expand Down
6 changes: 4 additions & 2 deletions Scripts/Web_Scrappers/COVID-19_Stats/requirement.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
beautifulsoup4
tabulate
bs4
tabulate
lxml
requests