Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
635 views
in Technique[技术] by (71.8m points)

r - RSelenium, Chrome, How to set download directory, file download error

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"
    )
    )
)

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'))
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

So try this:

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

Instead of this:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...