Skip to content

Instantly share code, notes, and snippets.

@microft
Created April 4, 2020 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save microft/773e7b04f88b048e5cd76e5654ef43ce to your computer and use it in GitHub Desktop.
Save microft/773e7b04f88b048e5cd76e5654ef43ce to your computer and use it in GitHub Desktop.
get the data from worldometers coronavirus page and display in console
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