-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdoc_sharepoint_files_download.R
78 lines (54 loc) · 2.49 KB
/
doc_sharepoint_files_download.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
if (!require("pacman")) install.packages("pacman")
pacman::p_load(RSelenium,
keyring
)
# unhcr user email -------------------------------------------------------
unhcr_user_email <- "[email protected]"
# insert list of sharepoint url -------------------------------------------
list_file_sharepoint <- c("https://unhcr365.sharepoint.com/teams/xxxx.xlsx",
"https://unhcr365.sharepoint.com/teams/xxxx.csv")
# path to download folder -------------------------------------------------
path_download_folder <- "C:\\Users\\folder1\\folder2"
# set download folder -----------------------------------------------------
eCap <- list("chromeOptions" = list(prefs = list("download.default_directory" = path_download_folder),
args = list('--headless')
)
)
rD <- rsDriver(browser = "chrome",
port=1245L,
chromever = "90.0.4430.24",
extraCapabilities = eCap)
remDr <- rD[["client"]]
# path to sharepoint ------------------------------------------------------
remDr$navigate("https://unhcr365.sharepoint.com")
# login to sharepoint -----------------------------------------------------
### insert email
webElem <-NULL
while(is.null(webElem)){
webElem <- tryCatch({remDr$findElement(using = "name", value = "loginfmt")},
error = function(e){NULL})
}
remDr$findElement(using = "name", value = "loginfmt")$sendKeysToElement(list(unhcr_user_email))
remDr$findElement(using = "id", value = "idSIButton9")$clickElement()
### insert password
Sys.sleep(1)
remDr$findElement(using = "name", value = "passwd")$sendKeysToElement(list(key_get("", # Please fill with service information
"[email protected]", # Please fill with username information
keyring ="") # Please fill with keyring information
))
### Lock keyring
keyring_lock(keyring = "") # Please fill with keyring information
Sys.sleep(1)
remDr$findElement(using = "id", value = "idSIButton9")$clickElement()
Sys.sleep(1)
### stay connect
remDr$findElement(using = "id", value = "idSIButton9")$clickElement()
Sys.sleep(1)
for(i in list_file_sharepoint){
Sys.sleep(1)
remDr$navigate(i)
}
rm(path_download_folder, unhcr_user_email,
list_file_sharepoint,
remDr, eCap, rD, webElem, i
)