我有一个循环(运行约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的摘录:
相关问题 更多 >
编程相关推荐