Last active
December 7, 2017 08:32
-
-
Save yaojenkuo/54a1df7437fc0a42c3b0d93f81d6513f to your computer and use it in GitHub Desktop.
get_zipped_csv.R
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
library(RSelenium) | |
# Define function | |
get_zipped_csv <- function(x) { | |
for (indicator in x) { | |
remDr$navigate("https://data.worldbank.org/") | |
query_box <- remDr$findElement(using = 'css', "#selector") | |
# Keyboard input | |
query_box$sendKeysToElement(list(indicator)) | |
Sys.sleep(5) | |
# Keyboard press enter | |
query_box$sendKeysToElement(list("\uE007")) | |
download_csv <- remDr$findElement(using = 'xpath', "//div[@class='btn-item download']/p/a[1]") | |
# Mouse click | |
download_csv$clickElement() | |
} | |
} | |
# Initiate the connection | |
remDr <- remoteDriver(remoteServerAddr = "localhost" | |
, port = 4444L | |
, browserName = "chrome" | |
) | |
remDr$open() | |
search_indicators <- c("gdp per capita", "life expectancy", "population") | |
# Call function | |
get_zipped_csv(search_indicators) | |
remDr$close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment