如何设置下载目录

如何设置下载目录

本文介绍了RSelenium,Chrome,如何设置下载目录,文件下载错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好 :) 我正在尝试从 XYZ 网站自动下载电子表格.该代码运行良好,通过授权没有问题并下载文件.但是,当我尝试更改下载目录时,它开始下载文件,但立即在浏览器中给我文件下载错误.我尝试更改下载目录的方式是添加:

Hello :) I'm trying to automate downloading spreadsheets from XYZ website. The code works well, goes through authorization without problem and downloads the file. But, when I try to change the download directory, it starts to download the file, but instantly gives me file download error in browser. The way I tried to change the download directory is by adding:

eCaps <- list(
  chromeOptions =
    list(prefs = list("profile.default_content_settings.popups" = 0L,
"download.prompt_for_download" = FALSE,
"directory_upgrade" = TRUE,
"download.default_directory" = "C:/XXX/YYY"
    )
    )
)

并将 extraCapabilities = eCaps 添加到 rsDrive():

and adding the extraCapabilities = eCaps to rsDrive():

rD <- rsDriver(browser= "chrome", chromever = "80.0.3987.16", extraCapabilities = eCaps)

没有这两个更改代码运行良好,下载到默认下载目录.有没有办法正确设置它以下载到任何其他目录?完整代码如下:

Without these two changes code worked well, downloading to default download directory. Is there any way to set it properly to download to any other directory?Here is the complete code:

library(RSelenium)
eCaps <- list(
  chromeOptions =
    list(prefs = list("profile.default_content_settings.popups" = 0L,
"download.prompt_for_download" = FALSE,
"directory_upgrade" = TRUE,
"download.default_directory" = "C:/XXX/YYY"
    )
    )
)
rD <- rsDriver(browser= "chrome", chromever = "80.0.3987.16", extraCapabilities = eCaps)
remDr <- rD$client

appURL <- 'https://XYZ'
remDr$navigate(appURL)
remDr$findElement("id", "loginEmail")$sendKeysToElement(list("email"))
remDr$findElement("id", "loginPassword")$sendKeysToElement(list("password", key='enter'))

appURL2 <- "https://XYZ/XYZ"
remDr$navigate(appURL2)
remDr$navigate(appURL2)

remDr$findElement("link text", "XLSX")$sendKeysToElement(list(key='enter'))

推荐答案

我遇到了同样的问题,这是有效的解决方案:

I ran into this same problem and here's the solution that worked:

出于某种原因,您需要在 download.default_directory 路径中使用双反斜杠,而不是单正斜杠.

For some reason, you need to use double backslashes in the download.default_directory path, rather than single forward slashes.

所以试试这个:

"download.default_directory" = "C:\XXX\YYY"

而不是这个:

"download.default_directory" = "C:/XXX/YYY"

这篇关于RSelenium,Chrome,如何设置下载目录,文件下载错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 06:28