几个月以来,我一直在使用来自perl的这样的网址:
http://finance.yahoo.com/d/quotes.csv?s=$s&f=ynl1 #returns yield, name, price;
今天,11/1/17,它突然返回999错误。
这是小故障,还是Yahoo终止了服务?
即使我直接在浏览器中输入URL,也会收到错误消息,例如:
http://finance.yahoo.com/d/quotes.csv?s=INTC&f=ynl1
因此这似乎不是一个“麻烦”的问题。
注意:这不是过去已回答的问题!
它昨天工作了,它在本月的第一天发生令人怀疑。
最佳答案
如其他答案和其他地方(例如https://stackoverflow.com/questions/47076404/currency-helper-of-yahoo-sorry-unable-to-process-request-at-this-time-erro/47096766#47096766)中所述,雅虎确实已经停止了Yahoo Finance API的操作。不过,作为一种解决方法,您可以通过对https://finance.yahoo.com/quote/SYMBOL(例如https://finance.yahoo.com/quote/MSFT)执行HTTPS GET请求,以给定的股票代码来访问JSON格式的大量财务信息。如果您对上述URL进行GET请求,您将看到财务数据以JSON格式包含在响应中。以下python3脚本显示了如何解析您可能感兴趣的单个值:
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 - 雅虎今天突然终止了其财务下载API吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47064776/