Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在RSelenium中指定下载文件夹_R_Google Chrome_Rselenium - Fatal编程技术网

在RSelenium中指定下载文件夹

在RSelenium中指定下载文件夹,r,google-chrome,rselenium,R,Google Chrome,Rselenium,我正在使用RSelenium导航到一个包含下载文件按钮的网页。我使用RSelenium单击此按钮下载文件。但是,默认情况下,文件下载到我的文件夹“downloads”中,而我希望文件下载到我的工作目录中。我尝试按以下方式指定chrome配置文件,但这似乎不起作用: wd <- getwd() cprof <- getChromeProfile(wd, "Profile 1") remDr <- remoteDriver(browserName= "chrome", extraC

我正在使用
RSelenium
导航到一个包含下载文件按钮的网页。我使用RSelenium单击此按钮下载文件。但是,默认情况下,文件下载到我的文件夹“downloads”中,而我希望文件下载到我的工作目录中。我尝试按以下方式指定chrome配置文件,但这似乎不起作用:

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

wd我一直在尝试其他选择,似乎@Bharath的第一条评论是放弃摆弄prefs(似乎不可能这么做),而是将文件从默认下载文件夹移动到所需文件夹。使其成为可移植解决方案的诀窍在于找到默认下载目录的位置()-当然,您还需要:


desired_dir解决方案包括设置在中列出的相应色度选项。以下是windows 10框的一个示例:

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)
ECAP以另一种方式查看。
您的下载文件夹应为空

列出文件夹中的文件
down.list可能尝试浏览将文件从下载文件夹移动到所需文件夹的方法。这已在下面的链接中解决[该问题是关于Python中的Selenium。我的问题是关于R中作为包的RSelenium。我理解参数“browser.download.dir”可以解决这个问题,但与RSelenium相关的文档似乎不支持这个说法……我知道firefox R支持“browser.download.dir”,但chrome的情况似乎不是这样。[访问此链接了解如何将此答案连接到[此].在firefox的地址栏中键入about:config以更改firefox浏览器的配置文件并获得您的答案这可以通过设置适当的chromeOptions来完成参见示例这会在启动时更改下载目录;在chrome开始使用代码后有没有办法更改它?@jdharison
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"