Skip to content

Instantly share code, notes, and snippets.

@deeplook
Created March 27, 2020 08:02
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 deeplook/b8c51a2d5661a0b465ec3cc35991ae19 to your computer and use it in GitHub Desktop.
Save deeplook/b8c51a2d5661a0b465ec3cc35991ae19 to your computer and use it in GitHub Desktop.
Scrape from the ESRI COVID-19 dashboard the total worldwide number of infections.
#!/usr/bin/env python
"""
Scrape from the ESRI COVID-19 dashboard the total worldwide number of infections.
This needs:
- Firefox
- conda install -c conda-forge geckodriver
- pip install selenium
Todo:
- Use a more selective XPATH expression.
"""
import re
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.headless = True
driver = webdriver.Firefox(options=options, executable_path='geckodriver')
url = ("https://gisanddata.maps.arcgis.com/"
"apps/opsdashboard/index.html#/bda7594740fd40299423467b48e9ecf6")
driver.get(url)
elem = driver.find_element_by_xpath("//html/body")
text = elem.text
driver.quit()
m = re.search("Total Confirmed\s*([\d,]+)", text)
total_confirmed = m.groups()[0]
total_confirmed = int(total_confirmed.replace(",", ""))
print(total_confirmed)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment