雅虎今天突然终止了它的金融下载 API 吗? [英] Has Yahoo suddenly today terminated its finance download API?

查看:32
本文介绍了雅虎今天突然终止了它的金融下载 API 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

For months I've been using a url like this, from perl:

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

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

Today, 11/1/17, it suddenly returns a 999 error.

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

Is this a glitch, or has Yahoo terminated the service?

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

I get the error even if I enter the URL directly into a browser as, eg:

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

所以这似乎不是面包屑"问题.

so it doesn't seem to be a 'crumb' problem.

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

Note: This is NOT a question which has been answered in the past! It was working yesterday.That it happened on the first of the month is suspicious.

推荐答案

如其他答案和其他地方所述(例如 https://stackoverflow.com/questions/47076404/currency-helper-of-yahoo-sorry-unable-to-process-request-at-this-time-erro/47096766#47096766),雅虎确实停止了雅虎财经 API 的运行.但是,作为一种解决方法,您可以通过向以下地址发送 HTTPS GET 请求,以 JSON 格式访问给定股票代码的大量财务信息:https://finance.yahoo.com/quote/SYMBOL(例如 https://finance.yahoo.com/quote/MSFT).如果您对上述 URL 发出 GET 请求,您将看到财务数据包含在 JSON 格式的响应中.以下 python3 脚本显示了如何解析您可能感兴趣的单个值:

As noted in the other answers and elsewhere (e.g. https://stackoverflow.com/questions/47076404/currency-helper-of-yahoo-sorry-unable-to-process-request-at-this-time-erro/47096766#47096766), Yahoo has indeed ceased operation of the Yahoo Finance API. However, as a workaround, you can access a trove of financial information, in JSON format, for a given ticker symbol, by doing a HTTPS GET request to: https://finance.yahoo.com/quote/SYMBOL (e.g. https://finance.yahoo.com/quote/MSFT). If you do a GET request to the above URL, you'll see that the financial data is contained within the response in JSON format. The following python3 script shows how you can parse individual values that you may be interested in:

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=str(resp.content, '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)

这篇关于雅虎今天突然终止了它的金融下载 API 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆