作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个循环(运行约200次),以从YahooFinance获得以前的收盘价。此循环随机停止,并出现以下错误消息:
WARNING:root:Some characters could not be decoded, and were replaced with REPLACEMENT CHARACTER.
[...]
AttributeError 'nonetype' object has no attribute 'text'
from yahoofinancials import YahooFinancials
import csv
with open('instruments.csv', 'r') as csvfile:
instruments = csv.reader(csvfile, delimiter=',', quoting = csv.QUOTE_NONNUMERIC, quotechar='"')
for instrument in instruments:
symbol = instrument[0]
yahoo_financials = YahooFinancials(symbol)
price = yahoo_financials.get_prev_close_price()
最佳答案
解决方案:您可以创建符号列表,然后将此列表提供给YahooFincials api,然后执行请求,而不是遍历每个符号并询问价格。似乎该软件包可以很好地解决此问题,尽管需要一些时间。
这是doc的摘录:
from yahoofinancials import YahooFinancials
tech_stocks = ['AAPL', 'MSFT', 'INTC']
yahoo_financials_tech = YahooFinancials(tech_stocks)
tech_stock_price_data = yahoo_financials_tech.get_prev_close_price()
关于python - 从YahooFinance获取价格数据会导致: AttributeError 'nonetype' object has no attribute 'text' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52427828/
我无法删除调试器终端中的橙色 java API 请求。我想隐藏这些。我该怎么做呢? (见图) 我正在使用带有 Maven 的 Visual Studio Code。 Printscreen 我的代码片
我是一名优秀的程序员,十分优秀!