1: 安裝python: https://www.cnblogs.com/liyafei/articles/11550979.html
將python.exe加入 全局path
2: 安裝庫:(不需要了,使用baostock代替了)
3:提示錯誤:C:\MyFile\SoftWare\python\python.exe: No module named pip, ModuleNotFoundError: No module named
'pip' https://blog.csdn.net/haihonga/article/details/100168691
4: 安裝BAOSTOCK
https://bbs.pinggu.org/thread-6387812-1-1.html
http://baostock.com/baostock/index.php/A%E8%82%A1K%E7%BA%BF%E6%95%B0%E6%8D%AE
5:代碼:
import baostock as bs import pandas as pd # 登陸系統 lg = bs.login(user_id="anonymous", password="123456") # 顯示登陸返回信息print('login respond error_code:'+lg.error_code) # print('login respond error_msg:'+lg.error_msg) # 查詢季頻估值指標盈利能力,獲取2010年第二季度的數據 profit_list = [] rs_profit = bs.query_profit_data(code="sh.600000", year=2015, quarter=2) while (rs_profit.error_code == '0') & rs_profit.next(): profit_list.append(rs_profit.get_row_data()) result_profit = pd.DataFrame(profit_list, columns=rs_profit.fields) # 打印輸出 print(result_profit) # 結果集輸出到csv文件 # result_profit.to_csv( "C:\Users\i505385\Desktop\Hansen.csv", index=False ) # 登出系統 bs.logout()
結果:
完成。