Skip to content

Commit 273c4b5

Browse files
author
pedestrian001
committed
fix: update CLS telegraph endpoint
1 parent fcdbf25 commit 273c4b5

1 file changed

Lines changed: 27 additions & 3 deletions

File tree

akshare/stock_feature/stock_info.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,23 @@
66
https://stock.eastmoney.com/a/czpnc.html
77
"""
88

9+
import hashlib
910
from datetime import datetime
1011

1112
import pandas as pd
1213
import requests
1314

14-
from akshare.request import make_request_with_retry_json
1515
from akshare.utils.cons import headers
1616

1717

18+
def _get_cls_sign(params: dict) -> str:
19+
"""Generate CLS web API signature."""
20+
canonical = "&".join(
21+
f"{key}={params[key]}" for key in sorted(params, key=str.upper)
22+
)
23+
return hashlib.md5(hashlib.sha1(canonical.encode()).hexdigest().encode()).hexdigest()
24+
25+
1826
def stock_info_cjzc_em() -> pd.DataFrame:
1927
"""
2028
东方财富-财经早餐
@@ -198,8 +206,24 @@ def stock_info_global_cls(symbol: str = "全部") -> pd.DataFrame:
198206
:return: 财联社-电报
199207
:rtype: pandas.DataFrame
200208
"""
201-
url = "https://www.cls.cn/nodeapi/telegraphList"
202-
data_json = make_request_with_retry_json(url, max_retries=10, headers=headers)
209+
url = "https://www.cls.cn/v1/roll/get_roll_list"
210+
params = {
211+
"app": "CailianpressWeb",
212+
"os": "web",
213+
"sv": "8.7.9",
214+
"refresh_type": "1",
215+
"rn": "20",
216+
"last_time": "0",
217+
}
218+
params["sign"] = _get_cls_sign(params)
219+
cls_headers = {
220+
**headers,
221+
"Referer": "https://www.cls.cn/telegraph",
222+
}
223+
r = requests.get(url, params=params, headers=cls_headers)
224+
data_json = r.json()
225+
if str(data_json.get("errno")) != "0":
226+
raise ValueError(f"接口返回异常: {data_json}")
203227
temp_df = pd.DataFrame(data_json["data"]["roll_data"])
204228
big_df = temp_df.copy()
205229
big_df = big_df[["title", "content", "ctime", "level"]]

0 commit comments

Comments
 (0)