作者TreeMan (好啊...)
看板R_Language
標題Re: [問題] 利用R下載外匯資料
時間Thu Oct 11 12:02:40 2018
1. data_id_all: 指標代碼做成的字串
2. d1: 起始搜尋日期
3. d2: 當前日期
4. RKey: 你的Rkey
library(httr)
for(data_id in data_id_all){
file_name <- paste0(data_id, ".csv")
d1 <- "2005-01-01"
d2 <- as.character(Sys.Date())
url <- paste0("
https://stock-ai.com/ddl?s=", data_id, "&r=RKey&d1=",
d1, "&d2=", d2)
GET(url, write_disk(file_name, overwrite=TRUE))
}
這樣應該會把更新到最新日期的檔案,存到你要的資料夾
我想到比較自動化的方式...
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 218.166.77.146
※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1539230563.A.966.html
推 ericchin0404: T大萬分感謝 這完全是我要的 10/11 12:29
推 ericchin0404: 可以弱弱問write_disk跟裡面的參數overwrite是什麼 10/11 12:54
→ ericchin0404: 意思嗎 我查了可是看不懂 10/11 12:54
推 andrew43: 若目標檔案已存在要不要覆蓋 10/11 13:52
推 ericchin0404: 懂了感謝 10/11 19:19