简体   繁体   English

RSelenium、Chrome、如何设置下载目录、文件下载错误

[英]RSelenium, Chrome, How to set download directory, file download error

Hello :) I'm trying to automate downloading spreadsheets from XYZ website.您好 :) 我正在尝试从 XYZ 网站自动下载电子表格。 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"
    )
    )
)

and adding the extraCapabilities = eCaps to rsDrive():并将 extraCapabilities = eCaps 添加到 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:我遇到了同样的问题,这是有效的解决方案:

For some reason, you need to use double backslashes in the download.default_directory path, rather than single forward slashes.出于某种原因,您需要在 download.default_directory 路径中使用双反斜杠,而不是单正斜杠。

So try this: "download.default_directory" = "C:\\\\XXX\\\\YYY"所以试试这个:"download.default_directory" = "C:\\\\XXX\\\\YYY"

Instead of this: "download.default_directory" = "C:/XXX/YYY"而不是这个:"download.default_directory" = "C:/XXX/YYY"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM