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

use*_*305 33 api yahoo-finance

几个月来我一直在使用这样的网址,来自perl:

http://finance.yahoo.com/d/quotes.csv?s=$s&f=ynl1 #returns yield, name, price;
Run Code Online (Sandbox Code Playgroud)

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

这是一个小问题,还是雅虎终止了这项服务?

即使我将URL直接输入浏览器,我也会收到错误,例如:

http://finance.yahoo.com/d/quotes.csv?s=INTC&f=ynl1
Run Code Online (Sandbox Code Playgroud)

所以它似乎不是一个"碎屑"问题.

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

小智 17

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

我们注意到此服务的使用违反了雅虎的服务条款.因此,该服务正在停止.有关所有未来市场和股票数据研究,请参阅finance.yahoo.com.


mti*_*935 17

正如其他答案和其他地方所述(例如雅虎的货币助手 - 抱歉,目前无法处理请求 - 错误999),雅虎确实停止了雅虎财务API的运营.但是,作为一种解决方法,您可以通过执行HTTPS GET请求来访问给定的股票代码符号的JSON格式的大量财务信息:https://finance.yahoo.com/quote/SYMBOL(例如https: //finance.yahoo.com/quote/MSFT).如果您对上述URL执行GET请求,您将看到财务数据包含在JSON格式的响应中.以下python脚本显示了如何解析您可能感兴趣的单个值:

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
Run Code Online (Sandbox Code Playgroud)

脚本的输出应如下所示:

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
Run Code Online (Sandbox Code Playgroud)

  • @mbmast - 根据浏览器发送的标头,服务器对浏览器请求的响应可能有所不同。我刚才使用上面的 python 脚本再次测试,它产生了预期的结果。我还更新了 python3 的脚本。 (2认同)

Ale*_*oVD 6

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

我将https://github.com/pstadler/ticker.sh使用的方法改编成以下python hack,它从命令行获取符号列表并将一些变量输出为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} - {1:.2f}".format(
            i['regularMarketDayLow'], i['regularMarketDayHigh']))
        print(",".join([str(e) for e in a]))
Run Code Online (Sandbox Code Playgroud)

样品运行:

$ ./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
Run Code Online (Sandbox Code Playgroud)


Tho*_*eis 6

var API = "https://query1.finance.yahoo.com/v7/finance/quote?symbols=AAPL"; $.getJSON(API, function (json) {...});call抛出此错误:请求的资源上没有"Access-Control-Allow-Origin"标头.因此,不允许来源" http://www.microplan.at/sar "访问.