Download Excel Files with RSelenium

亡梦爱人 提交于 2019-12-12 20:23:35

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!