使用RSelenium下载Excel文件 [英] Download Excel Files with RSelenium

查看:113
本文介绍了使用RSelenium下载Excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我已经找到了一个类似的问题,关于pdf 此处。答案表明,应该可以指定 extraCapabilities

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

不幸的是,我无法弄清楚如何正确设置 extraCapabilities



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



修改



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

解决方案

这是一个例子:

 库(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

请注意,内容类型必须匹配




$($)$ $ $ $ $ $ $ $ $ $ [1]application / vnd.openxmlformats-officedocument.spreadsheetml.sheet

虽然你应该能够使用通配符,如 *


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.

解决方案

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 *.

这篇关于使用RSelenium下载Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆