我需要从数据库下载 Excel 文件(这是我无法提供代码的原因)。我可以使用 RSelenium
单击下载图标。接下来发生的是通常的对话窗口打开,询问我是否要保存文件或打开它。如何抑制此消息并将文件下载到文件夹中?
我发现了有关 pdf here 的类似问题。答案表明通过指定 extraCapability
应该可以实现:
remDr <- remoteDriver(remoteServerAddr = "localhost",
browserName = "firefox",
extraCapabilities = someCapabilities,
port = 4444)
不幸的是,我不知道如何正确设置extraCapability
。
有人可以告诉我一个方向吗?感谢您的帮助。
编辑
我知道提供的解决方案 here并希望能够使用extraCapability
-方法。
最佳答案
这是一个例子:
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
请注意 content type必须匹配:
library(httr)
HEAD(url)$headers$`content-type`
# [1] "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
尽管您应该能够使用 *
等通配符。
关于r - 使用 RSelenium 下载 Excel 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34679950/