在RSelenium中指定下载文件夹 [英] Specify download folder in RSelenium

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

问题描述

我正在使用 RSelenium 来浏览包含下载文件按钮的网页。我使用RSelenium单击此按钮下载文件。但是,这些文件默认情况下会下载到我的文件夹'downloads'中,而我想要将文件下载到我的工作目录中。我试着指定一个chrome配置文件,但是这似乎并没有完成这项工作:

  wd<  -  getwd()
cprof< - getChromeProfile(wd,Profile 1)
remDr< - remoteDriver(browserName =chrome,extraCapabilities = cprof)

该文件仍然下载到downloads文件夹中,而不是我的工作目录中。如何解决这个问题?解决方案包括设置在 https://sites.google.com/a/chromium.org/chromedriver/capabilities 。下面是一个Windows 10框中的例子:

pre code $ library $(RSelenium)
eCaps< - list(
chromeOptions =
list(prefs = list(
profile.default_content_settings.popups= 0L,
download.prompt_for_download= FALSE,
download.default_directory= C:/ temp / chromeDL



rD < - rsDriver(extraCapabilities = eCaps)
remDr < - rD $ client
remDr $ navigate(http://www.colorado.edu/conflict/peace/download/)
firstzip< - remDr $ findElement(xpath,// a [contains(@href ,'zip')])
firstzip $ clickElement()
> list.files(C:/ temp / chromeDL)
[1]peace.zip


I am using RSelenium to navigate towards a webpage which contains a button to download a file. I use RSelenium to click this button which downloads the file. However, the files are by default downloaded in my folder 'downloads', whereas I want to file to be downloaded in my working directory. I tried specifying a chrome profile as below but this did not seem to do the job:

wd <- getwd()
cprof <- getChromeProfile(wd, "Profile 1")
remDr <- remoteDriver(browserName= "chrome", extraCapabilities = cprof) 

The file is still downloaded in the folder 'downloads', rather than my working directory. How can this be solved?

解决方案

The solution involves setting the appropriate chromeOptions outlined at https://sites.google.com/a/chromium.org/chromedriver/capabilities . Here is an example on a windows 10 box:

library(RSelenium)
eCaps <- list(
  chromeOptions = 
    list(prefs = list(
      "profile.default_content_settings.popups" = 0L,
      "download.prompt_for_download" = FALSE,
      "download.default_directory" = "C:/temp/chromeDL"
    )
    )
)
rD <- rsDriver(extraCapabilities = eCaps)
remDr <- rD$client
remDr$navigate("http://www.colorado.edu/conflict/peace/download/")
firstzip <- remDr$findElement("xpath", "//a[contains(@href, 'zip')]")
firstzip$clickElement()
> list.files("C:/temp/chromeDL")
[1] "peace.zip"

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

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