R语言 批量下载财务报表

getsheets <- function(symbol,type,file){
  pre="http://money.finance.sina.com.cn/corp/go.php/vDOWN_";
  mid="/displaytype/4/stockid/";
  end="/ctrl/all.phtml";
  
  if(type=="BS"){
    url=paste(pre,"BalanceSheet",mid,symbol,end,sep="");
    destfile=paste(file,"BS_",symbol,".xls",sep="");
  }
  if(type=="PS"){
    url=paste(pre,"ProfitStatement",mid,symbol,end,sep="");
    destfile=paste(file,"PS_",symbol,".xls",sep="");
  }
  if(type=="CF"){
    url=paste(pre,"CashFlow",mid,symbol,end,sep="");
    destfile=paste(file,"CF_",symbol,".xls",sep="");
  }
  download.file(url, destfile);
}
c=c("600550","600192","600152","600644","600885","600151")
for(i in 1:length(c)){
  code=c[i]
  getsheets(code,"BS","D://dataset//")
}

  

猜你喜欢

转载自www.cnblogs.com/amosding/p/12376396.html