我正在尝试打印“值”,但过一会儿它抛出了索引错误。我已经检查了位置,那里还有更多条目
import pandas as pd
import os
import time
import datetime as datetime
path = "G:\ML\Investing\intraQuarter"
def Key_Stats(gather="Total Debt/Equity (mrq)"):
statspath = path+'/_KeyStats'
stock_list = [x[0] for x in os.walk(statspath)]
#print('stock_list : ',stock_list[1:10])
for each_dir in stock_list[1:]:
each_file = os.listdir(each_dir)
ticker = each_dir.split("_KeyStats\\")[1]
if len(each_file) > 0:
#parsing time from the html file
for file in each_file:
date_stamp = time.strptime(file, '%Y%m%d%H%M%S.html')
unix_time = time.mktime(date_stamp)
#print(date_stamp, unix_time)
full_file_path = each_dir+'/'+file
source = open(full_file_path, 'r').read()
value = source.split(gather+':</td><td class="yfnc_tabledata1">')[1].split('</td>')[0]
print(ticker+":", value)
time.sleep(0.1)
Key_Stats()