|
6 | 6 | https://stock.eastmoney.com/a/czpnc.html |
7 | 7 | """ |
8 | 8 |
|
| 9 | +import hashlib |
9 | 10 | from datetime import datetime |
10 | 11 |
|
11 | 12 | import pandas as pd |
12 | 13 | import requests |
13 | 14 |
|
14 | | -from akshare.request import make_request_with_retry_json |
15 | 15 | from akshare.utils.cons import headers |
16 | 16 |
|
17 | 17 |
|
| 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 | + |
18 | 26 | def stock_info_cjzc_em() -> pd.DataFrame: |
19 | 27 | """ |
20 | 28 | 东方财富-财经早餐 |
@@ -198,8 +206,24 @@ def stock_info_global_cls(symbol: str = "全部") -> pd.DataFrame: |
198 | 206 | :return: 财联社-电报 |
199 | 207 | :rtype: pandas.DataFrame |
200 | 208 | """ |
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}") |
203 | 227 | temp_df = pd.DataFrame(data_json["data"]["roll_data"]) |
204 | 228 | big_df = temp_df.copy() |
205 | 229 | big_df = big_df[["title", "content", "ctime", "level"]] |
|
0 commit comments