雅虎突然终止了财务下载API吗?

几个月来,我一直在使用这样的url,从Perl:

http://finance.yahoo.com/d/quotes.csv?s=$s&f=ynl1 #returns yield, name, price; 

今天,11/1/17,它突然返回999错误。

这是一个小故障,或雅虎终止服务?

即使我直接在浏览器中inputURL,我也会收到错误信息,例如:

 http://finance.yahoo.com/d/quotes.csv?s=INTC&f=ynl1 

所以它似乎不是一个“屑”的问题。

注意:这不是过去已经回答的问题! 它昨天正在工作,发生在这个月的第一个月是可疑的。

雅虎证实他们终止了这项服务:

我们注意到,这项服务被用来违反雅虎服务条款。 因此,该服务正在中断。 对于所有未来的市场和股票数据研究,请参阅finance.yahoo.com。

正如在其他答案和其他地方(如雅虎的货币助手 – 对不起,目前无法处理请求 – 错误999 )中指出的,雅虎确实停止了雅虎财经API的操作。 但是,作为解决方法,您可以通过执行https https://finance.yahoo.com/quote/SYMBOL (例如, https:// https:// https://finance.yahoo.com/quote/SYMBOL)来获取JSON格式的财务信息库(对于给定的股票代码) //finance.yahoo.com/quote/MSFT )。 如果您对上述URL执行GET请求,则会看到财务数据以JSON格式包含在响应中。 下面的python脚本显示了如何parsing您可能感兴趣的各个值:

 import requests import json symbol='MSFT' url='https://finance.yahoo.com/quote/' + symbol resp = requests.get(url) #parse the section from the html document containing the raw json data that we need #you can write jsonstr to a file, then open the file in a web browser to browse the structure of the json data r=resp.text.encode('utf-8') i1=0 i1=r.find('root.App.main', i1) i1=r.find('{', i1) i2=r.find("\n", i1) i2=r.rfind(';', i1, i2) jsonstr=r[i1:i2] #load the raw json data into a python data object data = json.loads(jsonstr) #pull the values that we are interested in name=data['context']['dispatcher']['stores']['QuoteSummaryStore']['price']['shortName'] price=data['context']['dispatcher']['stores']['QuoteSummaryStore']['price']['regularMarketPrice']['raw'] change=data['context']['dispatcher']['stores']['QuoteSummaryStore']['price']['regularMarketChange']['raw'] shares_outstanding=data['context']['dispatcher']['stores']['QuoteSummaryStore']['defaultKeyStatistics']['sharesOutstanding']['raw'] market_cap=data['context']['dispatcher']['stores']['QuoteSummaryStore']['summaryDetail']['marketCap']['raw'] trailing_pe=data['context']['dispatcher']['stores']['QuoteSummaryStore']['summaryDetail']['trailingPE']['raw'] earnings_per_share=data['context']['dispatcher']['stores']['QuoteSummaryStore']['defaultKeyStatistics']['trailingEps']['raw'] forward_annual_dividend_rate=data['context']['dispatcher']['stores']['QuoteSummaryStore']['summaryDetail']['dividendRate']['raw'] forward_annual_dividend_yield=data['context']['dispatcher']['stores']['QuoteSummaryStore']['summaryDetail']['dividendYield']['raw'] #print the values print 'Symbol:', symbol print 'Name:', name print 'Price:', price print 'Change:', change print 'Shares Outstanding:', shares_outstanding print 'Market Cap:', market_cap print 'Trailing PE:', trailing_pe print 'Earnings Per Share:', earnings_per_share print 'Forward Annual Dividend Rate:', forward_annual_dividend_rate print 'Forward_annual_dividend_yield:', forward_annual_dividend_yield 

脚本的输出应该如下所示:

 Symbol: MSFT Name: Microsoft Corporation Price: 84.14 Change: 0.08999634 Shares Outstanding: 7714590208 Market Cap: 649105637376 Trailing PE: 31.04797 Earnings Per Share: 2.71 Forward Annual Dividend Rate: 1.68 Forward_annual_dividend_yield: 0.02 

var API = "https://query1.finance.yahoo.com/v7/finance/quote?symbols=AAPL"; $.getJSON(API, function (json) {...}); 调用将引发此错误:否请求的资源上存在“Access-Control-Allow-Origin”标头。 原因' http://www.microplan.at '因此不允许访问。

还有一种方法可以通过查询finance.yahoo.com页面使用的一些API来获取这些数据。 不知道雅虎是否会像以前的API那样长期支持它(希望他们会这么做)。

我调整了https://github.com/pstadler/ticker.sh使用的方法到下面的python hack中,该命令从命令行获取一系列符号,并将一些variables输出为csv:

 #!/usr/bin/env python import sys import time import requests if len(sys.argv) < 2: print("missing parameters: <symbol> ...") exit() apiEndpoint = "https://query1.finance.yahoo.com/v7/finance/quote" fields = [ 'symbol', 'regularMarketVolume', 'regularMarketPrice', 'regularMarketDayHigh', 'regularMarketDayLow', 'regularMarketTime', 'regularMarketChangePercent'] fields = ','.join(fields) symbols = sys.argv[1:] symbols = ','.join(symbols) payload = { 'lang': 'en-US', 'region': 'US', 'corsDomain': 'finance.yahoo.com', 'fields': fields, 'symbols': symbols} r = requests.get(apiEndpoint, params=payload) for i in r.json()['quoteResponse']['result']: if 'regularMarketPrice' in i: a = [] a.append(i['symbol']) a.append(i['regularMarketPrice']) a.append(time.strftime( '%Y-%m-%d %H:%M:%S', time.localtime(i['regularMarketTime']))) a.append(i['regularMarketChangePercent']) a.append(i['regularMarketVolume']) a.append("{0:.2f} - {0:.2f}".format( i['regularMarketDayLow'], i['regularMarketDayHigh'])) print(",".join([str(e) for e in a])) 

样品运行:

 $ ./getquotePy.py AAPL GOOGL AAPL,174.5342,2017-11-07 17:21:28,0.1630961,19905458,173.60 - 173.60 GOOGL,1048.6753,2017-11-07 17:21:22,0.5749836,840447,1043.00 - 1043.00