diff --git a/akshare/stock_fundamental/stock_finance_ths.py b/akshare/stock_fundamental/stock_finance_ths.py index ff976189163..aa4df76ad2a 100644 --- a/akshare/stock_fundamental/stock_finance_ths.py +++ b/akshare/stock_fundamental/stock_finance_ths.py @@ -13,7 +13,7 @@ def stock_financial_abstract_ths( - symbol: str = "000063", indicator: str = "按报告期" + symbol: str = "000063", indicator: str = "按报告期" ) -> pd.DataFrame: """ 同花顺-财务指标-主要指标 @@ -28,8 +28,8 @@ def stock_financial_abstract_ths( url = f"https://basic.10jqka.com.cn/new/{symbol}/finance.html" headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " - "AppleWebKit/537.36 (KHTML, like Gecko) " - "Chrome/89.0.4389.90 Safari/537.36", + "AppleWebKit/537.36 (KHTML, like Gecko) " + "Chrome/89.0.4389.90 Safari/537.36", } r = requests.get(url, headers=headers) soup = BeautifulSoup(r.text, "lxml") @@ -56,6 +56,128 @@ def stock_financial_abstract_ths( return temp_df +def stock_financial_debt_ths( + symbol: str = "000063", indicator: str = "按报告期" +) -> pd.DataFrame: + """ + 同花顺-财务指标-资产负债表 + https://basic.10jqka.com.cn/api/stock/finance/000063_debt.json + :param symbol: 股票代码 + :type symbol: str + :param indicator: 指标; choice of {"按报告期", "按年度"} + :type indicator: str + :return: 同花顺-财务指标-资产负债表 + :rtype: pandas.DataFrame + """ + url = f"https://basic.10jqka.com.cn/api/stock/finance/{symbol}_debt.json" + headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " + "AppleWebKit/537.36 (KHTML, like Gecko) " + "Chrome/89.0.4389.90 Safari/537.36", + } + r = requests.get(url, headers=headers) + data_json = json.loads(json.loads(r.text)['flashData']) + df_index = [ + item[0] if isinstance(item, list) else item for item in data_json["title"] + ] + if indicator == "按报告期": + temp_df = pd.DataFrame( + data_json["report"][1:], columns=data_json["report"][0], index=df_index[1:] + ) + else: + temp_df = pd.DataFrame( + data_json["year"][1:], columns=data_json["year"][0], index=df_index[1:] + ) + temp_df = temp_df.T + temp_df.reset_index(inplace=True) + temp_df.rename(columns={"index": "报告期"}, inplace=True) + return temp_df + + +def stock_financial_benefit_ths( + symbol: str = "000063", indicator: str = "按报告期" +) -> pd.DataFrame: + """ + 同花顺-财务指标-利润表 + https://basic.10jqka.com.cn/api/stock/finance/000063_benefit.json + :param symbol: 股票代码 + :type symbol: str + :param indicator: 指标; choice of {"按报告期","按单季度", "按年度"} + :type indicator: str + :return: 同花顺-财务指标-利润表 + :rtype: pandas.DataFrame + """ + url = f"https://basic.10jqka.com.cn/api/stock/finance/{symbol}_benefit.json" + headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " + "AppleWebKit/537.36 (KHTML, like Gecko) " + "Chrome/89.0.4389.90 Safari/537.36", + } + r = requests.get(url, headers=headers) + data_json = json.loads(json.loads(r.text)['flashData']) + df_index = [ + item[0] if isinstance(item, list) else item for item in data_json["title"] + ] + if indicator == "按报告期": + temp_df = pd.DataFrame( + data_json["report"][1:], columns=data_json["report"][0], index=df_index[1:] + ) + elif indicator == "按单季度": + temp_df = pd.DataFrame( + data_json["simple"][1:], columns=data_json["simple"][0], index=df_index[1:] + ) + else: + temp_df = pd.DataFrame( + data_json["year"][1:], columns=data_json["year"][0], index=df_index[1:] + ) + temp_df = temp_df.T + temp_df.reset_index(inplace=True) + temp_df.rename(columns={"index": "报告期"}, inplace=True) + return temp_df + + +def stock_financial_cash_ths( + symbol: str = "000063", indicator: str = "按报告期" +) -> pd.DataFrame: + """ + 同花顺-财务指标-现金流量表 + https://basic.10jqka.com.cn/api/stock/finance/000063_cash.json + :param symbol: 股票代码 + :type symbol: str + :param indicator: 指标; choice of {"按报告期","按单季度", "按年度"} + :type indicator: str + :return: 同花顺-财务指标-现金流量表 + :rtype: pandas.DataFrame + """ + url = f"https://basic.10jqka.com.cn/api/stock/finance/{symbol}_cash.json" + headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " + "AppleWebKit/537.36 (KHTML, like Gecko) " + "Chrome/89.0.4389.90 Safari/537.36", + } + r = requests.get(url, headers=headers) + data_json = json.loads(json.loads(r.text)['flashData']) + df_index = [ + item[0] if isinstance(item, list) else item for item in data_json["title"] + ] + if indicator == "按报告期": + temp_df = pd.DataFrame( + data_json["report"][1:], columns=data_json["report"][0], index=df_index[1:] + ) + elif indicator == "按单季度": + temp_df = pd.DataFrame( + data_json["simple"][1:], columns=data_json["simple"][0], index=df_index[1:] + ) + else: + temp_df = pd.DataFrame( + data_json["year"][1:], columns=data_json["year"][0], index=df_index[1:] + ) + temp_df = temp_df.T + temp_df.reset_index(inplace=True) + temp_df.rename(columns={"index": "报告期"}, inplace=True) + return temp_df + + if __name__ == "__main__": stock_financial_abstract_ths_df = stock_financial_abstract_ths( symbol="000063", indicator="按报告期" @@ -71,3 +193,18 @@ def stock_financial_abstract_ths( symbol="000063", indicator="按单季度" ) print(stock_financial_abstract_ths_df) + stock_financial_debt_ths( + symbol="000063", indicator="按报告期" + ) + stock_financial_debt_ths_df = stock_financial_debt_ths( + symbol="000063", indicator="按年度" + ) + print(stock_financial_debt_ths_df) + stock_financial_benefit_ths_df = stock_financial_benefit_ths( + symbol="000063", indicator="按报告期" + ) + print(stock_financial_benefit_ths_df) + stock_financial_cash_ths_df = stock_financial_cash_ths( + symbol="000063", indicator="按单季度" + ) + print(stock_financial_cash_ths_df) diff --git a/docs/data/stock/stock.md b/docs/data/stock/stock.md index 1c436189ebb..84d837a20d1 100644 --- a/docs/data/stock/stock.md +++ b/docs/data/stock/stock.md @@ -10570,6 +10570,176 @@ print(stock_cash_flow_sheet_by_quarterly_em_df) [66 rows x 315 columns] ``` +#### 财务报表-同花顺 + +##### 资产负债表 + +接口: stock_financial_debt_ths + +目标地址: https://basic.10jqka.com.cn/api/stock/finance/000063_debt.json + +描述: 同花顺-财务指标-资产负债表 + +限量: 单次获取资产负债表所有历史数据 + +输入参数 + +| 名称 | 类型 | 描述 | +| --------- | ---- | ------------------------------------------------------------ | +| symbol | str | symbol="000063"; 股票代码 | +| indicator | str | indicator="按报告期"; choice of {"按报告期", "按年度", "按单季度"} | + +输出参数 + +| 名称 | 类型 | 描述 | +| ---- | ---- | ----------------- | +| - | - | 80 项,不逐一列出 | + +接口示例 + +```python +import akshare as ak + +stock_financial_debt_ths_df = stock_financial_debt_ths(symbol="000063", indicator="按年度") +print(stock_financial_debt_ths_df) +``` + +数据示例 + +``` + 报告期 报表核心指标 *所有者权益(或股东权益)合计 ... 少数股东权益 所有者权益(或股东权益)合计 负债和所有者权益(或股东权益)合计 +0 2022 595.43亿 ... 9.02亿 595.43亿 1809.54亿 +1 2021 532.88亿 ... 18.06亿 532.88亿 1687.63亿 +2 2020 461.23亿 ... 28.26亿 461.23亿 1506.35亿 +3 2019 379.54亿 ... 28.75亿 379.54亿 1412.02亿 +4 2018 329.61亿 ... 38.11亿 329.61亿 1293.51亿 +5 2017 453.80亿 ... 44.12亿 453.80亿 1439.62亿 +6 2016 408.85亿 ... 51.63亿 408.85亿 1416.41亿 +7 2015 433.49亿 ... 43.67亿 433.49亿 1248.32亿 +8 2014 262.93亿 ... 14.14亿 262.93亿 1062.14亿 +9 2013 236.26亿 ... 10.93亿 236.26亿 1000.79亿 +10 2012 225.93亿 ... 11.36亿 225.93亿 1074.46亿 +11 2011 262.89亿 ... 20.57亿 262.89亿 1053.68亿 +12 2010 249.62亿 ... 18.68亿 249.62亿 841.52亿 +13 2009 179.49亿 ... 11.24亿 179.49亿 683.42亿 +14 2008 151.84亿 ... 9.34亿 151.84亿 508.66亿 +15 2007 128.88亿 ... 7.51亿 128.88亿 391.73亿 +16 2006 113.26亿 ... 5.62亿 113.26亿 257.61亿 +17 2005 105.96亿 ... 4.71亿 105.96亿 217.79亿 +18 2004 96.39亿 ... 4.65亿 96.39亿 208.30亿 +19 2003 52.77亿 ... 2.33亿 52.77亿 157.67亿 +20 2002 46.04亿 ... 2.17亿 46.04亿 122.17亿 +21 2001 39.18亿 ... 9910.63万 39.18亿 90.55亿 +22 2000 19.50亿 ... 6403.16万 19.50亿 63.21亿 +23 1999 15.79亿 ... 4952.78万 15.79亿 33.85亿 +24 1998 9.60亿 ... 2223.74万 9.60亿 21.94亿 +25 1997 7.01亿 ... 589.60万 7.01亿 13.57亿 +26 1996 1.30亿 ... 10.00万 1.30亿 3.83亿 +27 1995 7839.06万 ... False 7839.06万 2.36亿 +28 1994 4254.78万 ... False 4254.78万 1.45亿 + +[29 rows x 80 columns] +``` + +##### 利润表 + +接口: stock_financial_benefit_ths + +目标地址: https://basic.10jqka.com.cn/api/stock/finance/000063_benefit.json + +描述: 同花顺-财务指标-利润表 + +限量: 单次获取利润表所有历史数据 + +输入参数 + +| 名称 | 类型 | 描述 | +| --------- | ---- | ------------------------------------------------------------ | +| symbol | str | symbol="000063"; 股票代码 | +| indicator | str | indicator="按报告期"; choice of {"按报告期", "按年度", "按单季度"} | + +输出参数 + +| 名称 | 类型 | 描述 | +| ---- | ---- | ----------------- | +| - | - | 45 项,不逐一列出 | + +接口示例 + +```python +import akshare as ak + +stock_financial_benefit_ths_df = stock_financial_benefit_ths(symbol="000063", indicator="按报告期") +print(stock_financial_benefit_ths_df) +``` + +数据示例 + +``` + 报告期 报表核心指标 *净利润 ... 八、综合收益总额 归属于母公司股东的综合收益总额 归属于少数股东的综合收益总额 +0 2023-09-30 77.57亿 ... 77.05亿 77.94亿 -8842.60万 +1 2023-06-30 53.92亿 ... 53.41亿 54.24亿 -8317.50万 +2 2023-03-31 26.14亿 ... 24.85亿 25.17亿 -3237.00万 +3 2022-12-31 77.92亿 ... 77.24亿 80.15亿 -2.90亿 +4 2022-09-30 66.90亿 ... 66.52亿 67.88亿 -1.36亿 +.. ... ... ... ... ... ... ... +95 1997-12-31 1.21亿 ... False False False +96 1997-06-30 4124.14万 ... False False False +97 1996-12-31 9905.67万 ... False False False +98 1995-12-31 7314.86万 ... False False False +99 1994-12-31 8071.26万 ... False False False + +[100 rows x 45 columns] +``` + +##### 现金流量表 + +接口: stock_financial_cash_ths + +目标地址: https://basic.10jqka.com.cn/api/stock/finance/000063_cash.json + +描述: 同花顺-财务指标-现金流量表 + +限量: 单次获取现金流量表所有历史数据 + +输入参数 + +| 名称 | 类型 | 描述 | +| --------- | ---- | ------------------------------------------------------------ | +| symbol | str | symbol="000063"; 股票代码 | +| indicator | str | indicator="按报告期"; choice of {"按报告期", "按年度", "按单季度"} | + +输出参数 + +| 名称 | 类型 | 描述 | +| ---- | ---- | ----------------- | +| - | - | 75 项,不逐一列出 | + +接口示例 + +```python +import akshare as ak + +stock_financial_cash_ths_df = stock_financial_cash_ths(symbol="000063", indicator="按单季度") +print(stock_financial_cash_ths_df) +``` + +数据示例 + + 报告期 报表核心指标 *现金及现金等价物净增加额 ... 加:现金等价物的期末余额 减:现金等价物的期初余额 间接法-现金及现金等价物净增加额 + 0 2023-09-30 15.54亿 ... + 1 2023-06-30 52.02亿 ... + 2 2023-03-31 26.73亿 ... False False False + 3 2022-12-31 107.72亿 ... + 4 2022-09-30 -77.82亿 ... + .. ... ... ... ... ... ... ... + 78 2004-03-31 -16.81亿 ... False False -16.81亿 + 79 2003-12-31 19.40亿 ... 19.40亿 + 80 2003-09-30 -10.76亿 ... -10.76亿 + 81 2003-06-30 13.89亿 ... 13.89亿 + 82 2003-03-31 -14.06亿 ... False False -14.06亿 + + [83 rows x 75 columns] #### 财务报表-东财-已退市股票 ##### 资产负债表-按报告期