谷歌金融getprices网址通过浏览器工作,但不是从编程方式从R

谷歌金融getprices网址通过浏览器工作,但不是从编程方式从R

问题描述:

此网址https://finance.google.com/finance/getprices?i=60&p=1d&f=d,l,h&q=ALV返回预计在谷歌单日在ALV一分钟的价格。谷歌金融getprices网址通过浏览器工作,但不是从编程方式从R

library(data.table); fread(“https://finance.google.com/finance/getprices?i=60&p=1d&f=d,l,h&q=ALV”,sep =“/ n”)

一直工作到昨天(9/14/17)。现在它只返回标题信息并且不返回一分钟数据。就好像在一分钟数据前插入了EOF。我也尝试过R中的getURL()和其他方法,结果相同。

有关如何获取R中一分钟数据的任何建议?或成任何文件格式?

奇怪了,这对我的作品有RStudio版本1.0.136 & [R版本3.3.3:

library(data.table) 
library(xts) 

url = "https://finance.google.com/finance/getprices?i=60&p=1d&f=d,o,h,l,c,v&q=AAPL"  
data = tryCatch({ fread(url) }, error = function(cond) { return(NULL) }) 
if(is.null(data)) { 
    print(paste('Error getting data from', url)) 
} 

# swap columns since google places close price first 
data = data[,c(1,5,3,4,2,6)] 
colnames(data) = c('Date','Open','High','Low','Close','Volume') 
# get start unix time 
data$Date = as.double(gsub('a','',data$Date)) 
# add to rest 
data$Date[-1] = data$Date[-1]*60 + data$Date[1] 
# make xts 
data = xts(data[,2:6], order.by = as.POSIXct(data$Date, origin='1970-01-01')) 

这给了我最最近的1分数据。

+0

谢谢Ole。我正在运行3.4.0和data.table 1.10.4。现在它也适用于我。我想知道谷歌是否有一个呃。感谢您的努力和漂亮的代码。 – Marc