Created
July 16, 2020 12:31
-
-
Save a4amaan/1131cac0c0b99e6e07903aa05fa1dbe9 to your computer and use it in GitHub Desktop.
Scrape Html Table Data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
url = "https://globalhealth5050.org/covid19/sex-disaggregated-data-tracker/" | |
html_content = requests.get(url).text | |
soup = BeautifulSoup(html_content, "lxml") | |
table_rows = soup.find("table", attrs={"id": "table_1"}).find("tbody").find_all("tr") | |
for row in table_rows: | |
cells = row.find_all("td") | |
country_code = cells[0].get_text() | |
country = find(country_code=country_code) | |
date = cells[3].get_text() | |
cases_percentage_male = cells[5].get_text() | |
cases_percentage_female = cells[6].get_text() | |
deaths_percentage_male = cells[8].get_text() | |
deaths_percentage_female = cells[9].get_text() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment