2017-05-29 206 views
0

雅虎财经最近将其历史数据网址从http更改为https。例如,下面是获得IBM的最大历史URL(截至今日,2017年5月29日):R:从雅虎财经下载历史数据

https://query1.finance.yahoo.com/v7/finance/download/IBM?period1=-252345600&period2=1496041200&interval=1d&events=history&crumb=jIIyoewBT2o 

当我尝试从内部RI阅读资源得到如下:

> url = 'https://query1.finance.yahoo.com/v7/finance/download/IBM?period1=-252345600&period2=1496041200&interval=1d&events=history&crumb=jIIyoewBT2o' 
> read.csv(url) 
Error in file(file, "rt") : 
    (converted from warning) cannot open URL 'https://query1.finance.yahoo.com/v7/finance/download/IBM?period1=-252345600&period2=1496041200&interval=1d&events=history&crumb=jIIyoewBT2o': HTTP status was '401 Unauthorized' 

当通过浏览器手动调用时,下载工作正常,所以它不像Yahoo Finance试图阻止访问数据。很显然,浏览器正在向雅虎服务器发送一些秘密的内容。我可以通过R脚本发送相同的秘密酱汁吗?

+0

检查[此](https://stackoverflow.com/questions/44083891/started-to-get-error-while-downloading-data-from-yahoo-finance-using-r/)。 – Eldioo

+0

请参阅此链接:https://stackoverflow.com/questions/44015838/cant-download-data-from-yahoo-finance-using-quantmod-in-r?noredirect=1&lq=1 – Dave2e

回答

0

我想雅虎几个月前就放弃了它的API。如果你想要一个Excel解决方案,您可以从标题链接的样本文件“获取Excel电子表格,从谷歌财经下载批量历史库存数据”

http://investexcel.net/multiple-stock-quote-downloader-for-excel/

enter image description here

对于R,做一些事情喜欢这个。

library(BatchGetSymbols) 

first.date <- Sys.Date()-365 
last.date <- Sys.Date() 

df.SP500 <- GetSP500Stocks() 
tickers <- df.SP500$tickers 

l.out <- BatchGetSymbols(tickers = tickers, 
         first.date = first.date, 
         last.date = last.date) 

print(l.out$df.control) 
print(l.out$df.tickers)