Created
March 27, 2020 08:02
-
-
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.
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
#!/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