你好:(我正在尝试从XYZ网站自动下载电子表格。该代码运行良好,可以顺利通过授权并下载文件。但是,当我尝试更改下载目录时,它开始下载文件,但立即在浏览器中给我文件下载错误。我尝试更改下载目录的方式是添加:
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((:
rD <- rsDriver(browser= "chrome", chromever = "80.0.3987.16", extraCapabilities = eCaps)
没有这两个更改,代码运行良好,下载到默认下载目录。有没有办法将其正确设置为下载到任何其他目录?这是完整的代码:
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'))
我遇到了同样的问题,下面是有效的解决方案:
出于某种原因,您需要在download.default_directory路径中使用双反斜杠,而不是单正斜杠。
所以试试这个:
"download.default_directory" = "C:\XXX\YYY"
取而代之的是:
"download.default_directory" = "C:/XXX/YYY"