问题
I need to download an excel-file from a database (the reason that I cannot provide code). I'm able to click on the download icon using RSelenium
. What happens next is that the usual dialogue-window opens asking me if I want to save the file or open it. How can I suppress this message and download the file into a folder?
I have found a similar question regarding pdf here. The answer suggests it should be possible by specifying of the extraCapabilities
:
remDr <- remoteDriver(remoteServerAddr = "localhost",
browserName = "firefox",
extraCapabilities = someCapabilities,
port = 4444)
Unfortunately, I couldn't figure out how to set extraCapabilities
correctly.
Can somebody hint me in a direction? Thanks for help.
Edit
I'm aware of the solution provided here and hope to be able to use the extraCapabilities
-Approach.
回答1:
Here's an example:
library(RSelenium)
startServer()
remDr <- remoteDriver(extraCapabilities = makeFirefoxProfile(list(
"browser.helperApps.neverAsk.saveToDisk"="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
))
remDr$open()
url <- "http://www.iwh-halle.de/e/fdz/IntBankLib/data/downloads/databases.xlsx"
remDr$navigate(url)
file.exists(file.path("~/Downloads/", basename(url)))
# [1] TRUE
Note that the content type has to match:
library(httr)
HEAD(url)$headers$`content-type`
# [1] "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Although you should be able to use wildcards like *
.
来源:https://stackoverflow.com/questions/34679950/download-excel-files-with-rselenium