【问题标题】:Download Excel Files with RSelenium使用 RSelenium 下载 Excel 文件
【发布时间】:2016-01-08 14:58:12
【问题描述】:

我需要从数据库下载一个 excel 文件(我无法提供代码的原因)。我可以使用RSelenium 单击下载图标。接下来发生的是通常的对话窗口打开,询问我是否要保存文件或打开它。如何隐藏此消息并将文件下载到文件夹中?

我发现了一个关于 pdf here 的类似问题。答案表明应该可以通过指定extraCapabilities

remDr <- remoteDriver(remoteServerAddr = "localhost", 
                  browserName = "firefox",
                  extraCapabilities = someCapabilities,
                  port = 4444)

不幸的是,我不知道如何正确设置extraCapabilities

有人可以提示我一个方向吗?感谢您的帮助。

编辑

我知道here 提供的解决方案,并希望能够使用extraCapabilities-Approach。

【问题讨论】:

    标签: r excel rselenium


    【解决方案1】:

    这是一个例子:

    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"
    

    虽然您应该能够使用像* 这样的通配符。

    【讨论】:

    • makeFirefoxProfile(...) 命令返回错误:文件中的错误(tmpfile,“rb”):无法打开连接另外:警告消息:1:运行命令“zip”-r9Xjq“C :\Users\rockscience\AppData\Local\Temp\RtmpoPhjUb\file31028ad12f9.zip" "C:\Users\rockscience\AppData\Local\Temp\RtmpoPhjUb/firefoxprofile/prefs.js" ' 状态为 127 2:在文件中(tmpfile , "rb") : 无法打开文件'C:\Users\rockscience\AppData\Local\Temp\RtmpoPhjUb\file31028ad12f9.zip': 没有这样的文件或目录
    • 可能是因为我在 docker 中运行 selenium?
    • 对不起,我不知道。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-31
    • 1970-01-01
    相关资源
    最近更新 更多