From 0007bbac5eeecb4502e7c6ab8725f6594399f611 Mon Sep 17 00:00:00 2001 From: eborchardt Date: Fri, 4 Mar 2022 17:50:52 +0000 Subject: [PATCH 1/2] fixed errors in script, removed references to recovered fields, and added additional required modules to requirement.txt --- .../COVID-19_Stats/COVID-19_scraper.py | 46 ++++++++++--------- .../COVID-19_Stats/requirement.txt | 6 ++- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/Scripts/Web_Scrappers/COVID-19_Stats/COVID-19_scraper.py b/Scripts/Web_Scrappers/COVID-19_Stats/COVID-19_scraper.py index 6ad46eceb..0f07c0592 100644 --- a/Scripts/Web_Scrappers/COVID-19_Stats/COVID-19_scraper.py +++ b/Scripts/Web_Scrappers/COVID-19_Stats/COVID-19_scraper.py @@ -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 @@ -40,20 +44,20 @@ 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 +# 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], +# ["Recovered", " : ", ttlRecovered], [], [], ] - print(makeTable(table, [], "plain")) + print(makeTable(table, [], "plain")) print("Enter 0 to terminate") statsFind() except: @@ -69,14 +73,14 @@ 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 +# ttlRecovered = soup.select_one("tr.sorttop > th:nth-child(5)").text table = [ ["Total cases", " : ", ttlCase], ["Total deaths", " : ", ttlDeaths], - ["Total people recovered", " : ", ttlRecovered], +# ["Total people recovered", " : ", ttlRecovered], ] print( @@ -87,13 +91,13 @@ 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]) + # ttlRecovered = soup.select_one(" tr:nth-child({}) > td:nth-child(5)".format(i)).text + top10.append([i - 2, country, ttlCase, ttlDeaths]) print(makeTable(top10, header, "grid")) diff --git a/Scripts/Web_Scrappers/COVID-19_Stats/requirement.txt b/Scripts/Web_Scrappers/COVID-19_Stats/requirement.txt index 64a494460..5eeed7cd7 100644 --- a/Scripts/Web_Scrappers/COVID-19_Stats/requirement.txt +++ b/Scripts/Web_Scrappers/COVID-19_Stats/requirement.txt @@ -1,2 +1,4 @@ -beautifulsoup4 -tabulate \ No newline at end of file +bs4 +tabulate +lxml +requests From cb287fb52ef0d0cd7fcb467ef277b8e2f9d7bc43 Mon Sep 17 00:00:00 2001 From: eborchardt <56270998+eborchardt@users.noreply.github.com> Date: Fri, 4 Mar 2022 12:25:09 -0600 Subject: [PATCH 2/2] Update COVID-19_scraper.py --- Scripts/Web_Scrappers/COVID-19_Stats/COVID-19_scraper.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/Scripts/Web_Scrappers/COVID-19_Stats/COVID-19_scraper.py b/Scripts/Web_Scrappers/COVID-19_Stats/COVID-19_scraper.py index 0f07c0592..414e940d7 100644 --- a/Scripts/Web_Scrappers/COVID-19_Stats/COVID-19_scraper.py +++ b/Scripts/Web_Scrappers/COVID-19_Stats/COVID-19_scraper.py @@ -44,16 +44,10 @@ 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], [], [], ] @@ -75,12 +69,10 @@ def statsFind(): ttlCase = soup.select_one("tr.sorttop > td:nth-child(3)").text ttlDeaths = soup.select_one("tr.sorttop > td:nth-child(4)").text -# ttlRecovered = soup.select_one("tr.sorttop > th:nth-child(5)").text table = [ ["Total cases", " : ", ttlCase], ["Total deaths", " : ", ttlDeaths], -# ["Total people recovered", " : ", ttlRecovered], ] print( @@ -96,7 +88,6 @@ def statsFind(): 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]) print(makeTable(top10, header, "grid"))