gpt4 book ai didi

python - 从YahooFinance获取价格数据会导致: AttributeError 'nonetype' object has no attribute 'text'

转载 作者:行者123 更新时间:2023-12-03 08:46:35 24 4
gpt4 key购买 nike

我有一个循环(运行约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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com