From 079d89db9a2fb657b8557f5a0bc053499667a1a5 Mon Sep 17 00:00:00 2001 From: jindaxiang Date: Wed, 24 Jul 2024 23:45:33 +0800 Subject: [PATCH] fix: fix stock_hold_num_cninfo --- akshare/stock/stock_hold_num_cninfo.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/akshare/stock/stock_hold_num_cninfo.py b/akshare/stock/stock_hold_num_cninfo.py index afb051254ba..85e07f1a8cd 100644 --- a/akshare/stock/stock_hold_num_cninfo.py +++ b/akshare/stock/stock_hold_num_cninfo.py @@ -1,14 +1,14 @@ #!/usr/bin/env python # -*- coding:utf-8 -*- """ -Date: 2023/5/30 00:19 +Date: 2024/7/24 23:30 Desc: 巨潮资讯-数据中心-专题统计-股东股本-股东人数及持股集中度 -http://webapi.cninfo.com.cn/#/thematicStatistics +https://webapi.cninfo.com.cn/#/thematicStatistics """ import pandas as pd -import requests import py_mini_racer +import requests from akshare.datasets import get_ths_js @@ -22,7 +22,7 @@ def _get_file_content_ths(file: str = "cninfo.js") -> str: :rtype: str """ setting_file_path = get_ths_js(file) - with open(setting_file_path) as f: + with open(setting_file_path, encoding="utf-8") as f: file_data = f.read() return file_data @@ -30,13 +30,13 @@ def _get_file_content_ths(file: str = "cninfo.js") -> str: def stock_hold_num_cninfo(date: str = "20210630") -> pd.DataFrame: """ 巨潮资讯-数据中心-专题统计-股东股本-股东人数及持股集中度 - http://webapi.cninfo.com.cn/#/thematicStatistics + https://webapi.cninfo.com.cn/#/thematicStatistics :param date: choice of {"XXXX0331", "XXXX0630", "XXXX0930", "XXXX1231"}; 从 20170331 开始 :type date: str :return: 股东人数及持股集中度 :rtype: pandas.DataFrame """ - url = "http://webapi.cninfo.com.cn/api/sysapi/p_sysapi1034" + url = "https://webapi.cninfo.com.cn/api/sysapi/p_sysapi1034" js_code = py_mini_racer.MiniRacer() js_content = _get_file_content_ths("cninfo.js") js_code.eval(js_content) @@ -49,11 +49,12 @@ def stock_hold_num_cninfo(date: str = "20210630") -> pd.DataFrame: "Cache-Control": "no-cache", "Content-Length": "0", "Host": "webapi.cninfo.com.cn", - "Origin": "http://webapi.cninfo.com.cn", + "Origin": "https://webapi.cninfo.com.cn", "Pragma": "no-cache", "Proxy-Connection": "keep-alive", - "Referer": "http://webapi.cninfo.com.cn/", - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36", + "Referer": "https://webapi.cninfo.com.cn/", + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) " + "Chrome/93.0.4577.63 Safari/537.36", "X-Requested-With": "XMLHttpRequest", } params = { @@ -86,7 +87,7 @@ def stock_hold_num_cninfo(date: str = "20210630") -> pd.DataFrame: "人均持股数量增幅", ] ] - temp_df["变动日期"] = pd.to_datetime(temp_df["变动日期"]).dt.date + temp_df["变动日期"] = pd.to_datetime(temp_df["变动日期"], errors="coerce").dt.date temp_df["本期人均持股数量"] = pd.to_numeric( temp_df["本期人均持股数量"], errors="coerce" )