首页 > 解决方案 > 可以使用 csv 文件在 url 中下载多个 zip 文件吗?

问题描述

我有一个包含多个日期的 csv 文件,例如。日期示例

我想为 csv 文件中的每个日期下载多个 zip 文件。

在下面的具体示例中,日期为 20151117。有没有办法下载 csv 中的每个日期,也许是通过在下面的代码中包含 csv 文件?

download.file("https://www.quandl.com/api/v3/databases/OSMV/download?download_type=20151117&api_key=my_api_key", destfile = "/Users/anders/Documents/Juni 2019/DATA/datatest.zip", mode="wb", method="libcurl")

我希望我的问题有意义。

谢谢

标签: rurldownloadzipfilequandl

解决方案


这是一个应该起作用的小循环:

df <- data.frame(all_dates = c("20150711","20160613")) 
dates <- unique(df$all_dates) # create list of dates that you want

for (d in dates){ # each 'd' is one date

# create url to download from for each date
download.file(paste0("https://www.quandl.com/api/v3/databases/OSMV/download?download_type=", d, "&api_key=my_api_key", 

# create destination file with date in the file name
destfile = paste0("/Users/anders/Documents/Juni 2019/DATA/datatest", d, ".zip", 
mode="wb", method="libcurl"))
}

推荐阅读