通过 R 中的提交按钮下载 csv 文件
Download csv file via submit button in R
我想在 R 中自动执行以下任务:
进入历史数据如下页面:
http://www.ariva.de/XXX/historische_kurse,
其中 XXX 代表一些代码,例如DBX0BT
所以在这种情况下 URL 将是:
http://www.ariva.de/DBX0BT/historische_kurse
右下角有一个按钮Download
。
我想创建一个函数作为输入:
- 代码
- 从日期 (von)
- 迄今为止(之二)
- 路径
然后通过"pressing the Download
button"将生成的csv文件下载到path给出的位置路径。
我的问题
我如何在 R 中执行此操作?
只要您有 WKN or ISIN 的列表,您就可以 运行 这个和 read/download 个文件。您也可以抓取 WKN/ISINs,但是从这个网页上抓取会更加复杂,我假设您可以访问此类信息。
library(XML)
wkn<-c("DBX0BT","865985") #some stock IDs (WKN) for your targets
date.F<-"12.5.2014" #from when for historical data
date.T<-"12.5.2015" #to when
for(j in 1:length(wkn)){
tg<-htmlParse(paste0("http://www.ariva.de/",wkn[j],"/historische_kurse")) #parse the historical webpage
atbts<-xpathSApply(tg,'//div[@class="content left abstand"]/input') #extract attributes for that stock so we can download it
secu<-sapply(atbts, function(x) xmlAttrs(x)['value'])[1] #security id (only relevant for downloading)
boerseid<-sapply(atbts, function(x) xmlAttrs(x)['value'])[2] #boerse id (only relevant for downloading)
#download, read and assign the values
assign(wkn[j],read.csv(paste0("http://www.ariva.de/quote/historic/historic.csv?secu=",secu,"&boerse_id=",boerseid,
"&clean_split=1&clean_payout=0&clean_bezug=1&min_time=",date.F,"&max_time=",date.T,"&trenner=%3B&go=Download"),
sep=";"))
write.csv(get(wkn[j]),paste0(wkn[j],".csv"))
}
我想在 R 中自动执行以下任务:
进入历史数据如下页面: http://www.ariva.de/XXX/historische_kurse, 其中 XXX 代表一些代码,例如DBX0BT
所以在这种情况下 URL 将是: http://www.ariva.de/DBX0BT/historische_kurse
右下角有一个按钮Download
。
我想创建一个函数作为输入:
- 代码
- 从日期 (von)
- 迄今为止(之二)
- 路径
然后通过"pressing the Download
button"将生成的csv文件下载到path给出的位置路径。
我的问题
我如何在 R 中执行此操作?
只要您有 WKN or ISIN 的列表,您就可以 运行 这个和 read/download 个文件。您也可以抓取 WKN/ISINs,但是从这个网页上抓取会更加复杂,我假设您可以访问此类信息。
library(XML)
wkn<-c("DBX0BT","865985") #some stock IDs (WKN) for your targets
date.F<-"12.5.2014" #from when for historical data
date.T<-"12.5.2015" #to when
for(j in 1:length(wkn)){
tg<-htmlParse(paste0("http://www.ariva.de/",wkn[j],"/historische_kurse")) #parse the historical webpage
atbts<-xpathSApply(tg,'//div[@class="content left abstand"]/input') #extract attributes for that stock so we can download it
secu<-sapply(atbts, function(x) xmlAttrs(x)['value'])[1] #security id (only relevant for downloading)
boerseid<-sapply(atbts, function(x) xmlAttrs(x)['value'])[2] #boerse id (only relevant for downloading)
#download, read and assign the values
assign(wkn[j],read.csv(paste0("http://www.ariva.de/quote/historic/historic.csv?secu=",secu,"&boerse_id=",boerseid,
"&clean_split=1&clean_payout=0&clean_bezug=1&min_time=",date.F,"&max_time=",date.T,"&trenner=%3B&go=Download"),
sep=";"))
write.csv(get(wkn[j]),paste0(wkn[j],".csv"))
}