Created
April 4, 2020 09:31
-
-
Save microft/773e7b04f88b048e5cd76e5654ef43ce to your computer and use it in GitHub Desktop.
get the data from worldometers coronavirus page and display in console
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
from selenium import webdriver | |
from selenium.webdriver.chrome.options import Options | |
from tabulate import tabulate | |
chrome_options = Options() | |
chrome_options.add_argument("--headless") | |
driver = webdriver.Chrome(options=chrome_options) | |
driver.get('https://www.worldometers.info/coronavirus/') | |
output_table = [] | |
table = driver.find_element_by_xpath('//*[@id="main_table_countries_today"]/thead[1]') | |
row = table.find_elements_by_tag_name("tr")[0] # get all of the rows in the table | |
cells = row.find_elements_by_tag_name("th") | |
output_table.append([cell.text for cell in cells]) | |
output_table.append(['_' for x in cells]) | |
table = driver.find_element_by_xpath('//*[@id="main_table_countries_today"]/tbody[1]') | |
rows = table.find_elements_by_tag_name("tr") # get all of the rows in the table | |
for row in rows[:50]: | |
cells = row.find_elements_by_tag_name("td") | |
output_table.append([cell.text for cell in cells]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment