
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 获取所有股票的历史数据
def do_load(ak_code, ak_name, period, start_date, end_date, adj, timeout):
print(ak_code, ak_name)
for i in range(3):
try:
# 历史行情数据-后复权
df = ak.stock_zh_a_hist(symbol=ak_code, period=period, start_date=start_date, end_date=end_date, adjust=adj,
timeout=timeout)
if df.empty:
continue
if ak_code.startswith('6') == True:
df['股票代码'] = ak_code + '.SH'
elif ak_code.startswith('8') == True:
df['股票代码'] = ak_code + '.BJ'
else:
df['股票代码'] = ak_code + '.SZ'
df['股票名称'] = ak_name
df.sort_values(by=['日期'], ascending=True, inplace=True)
df.reset_index(drop=True, inplace=True)
path = create_path(ak_code)
df.to_csv(path, index=False, mode='w', encoding='gbk')
# 休眠指定的时间
time.sleep(random.uniform(300, 1000) / 100)
break # 成功运行后跳出循环
except Exception as e:
# 处理其他未特定捕获的异常
print("发生了其他异常!", e)

发布者:股市刺客,转载请注明出处:https://www.95sca.cn/archives/106014
站内所有文章皆来自网络转载或读者投稿,请勿用于商业用途。如有侵权、不妥之处,请联系站长并出示版权证明以便删除。敬请谅解!