mirror of
https://github.com/simonlin1212/TradingAgents-astock.git
synced 2026-10-30 09:29:56 +00:00
Merge pull request #111
This commit is contained in:
@@ -18,6 +18,7 @@ from typing import Annotated
|
||||
from datetime import date, datetime, timedelta, timezone
|
||||
from dateutil.relativedelta import relativedelta
|
||||
import contextlib
|
||||
import io
|
||||
import json as _json
|
||||
import os
|
||||
import logging
|
||||
@@ -611,7 +612,7 @@ def _ths_eps_forecast(code: str) -> pd.DataFrame:
|
||||
}
|
||||
r = _requests.get(url, headers=headers, timeout=15)
|
||||
r.encoding = "gbk"
|
||||
dfs = pd.read_html(r.text)
|
||||
dfs = pd.read_html(io.StringIO(r.text))
|
||||
# Find the table containing EPS data
|
||||
for df in dfs:
|
||||
cols = [str(c) for c in df.columns]
|
||||
@@ -1975,12 +1976,12 @@ def get_concept_blocks(
|
||||
code = _normalize_ticker(ticker)
|
||||
|
||||
try:
|
||||
url = (
|
||||
"https://finance.pae.baidu.com/api/getrelatedblock"
|
||||
f'?stock=[{{"code":"{code}","market":"ab","type":"stock"}}]'
|
||||
"&finClientType=pc"
|
||||
)
|
||||
r = requests.get(url, headers=_BAIDU_PAE_HEADERS, timeout=10)
|
||||
url = "https://finance.pae.baidu.com/api/getrelatedblock"
|
||||
params = {
|
||||
"stock": f'[{{"code":"{code}","market":"ab","type":"stock"}}]',
|
||||
"finClientType": "pc",
|
||||
}
|
||||
r = requests.get(url, params=params, headers=_BAIDU_PAE_HEADERS, timeout=10)
|
||||
d = r.json()
|
||||
|
||||
if str(d.get("ResultCode", -1)) != "0":
|
||||
@@ -1990,6 +1991,16 @@ def get_concept_blocks(
|
||||
)
|
||||
|
||||
result = d.get("Result", {})
|
||||
# 百度风控会回 HTTP 403 + {"ResultCode": 0(整数), "Result": {"code": 403,
|
||||
# "isCaptchaEnabled": true, "msg": "hit risk"}}。外层 ResultCode 是**整数** 0,
|
||||
# 上面那句 str() 比较放它过关,于是被风控当成"该股没有概念板块"——一个错的事实
|
||||
# 喂给模型。这里必须单独识别,把失败如实报出来。
|
||||
if isinstance(result, dict) and result.get("code") == 403:
|
||||
return (
|
||||
f"Baidu PAE 风控拦截(hit risk),{code} 的概念板块本次取不到。"
|
||||
"该接口会对 python-requests 的 TLS 指纹做风控(同一时刻 curl 正常),"
|
||||
"需 curl_cffi 浏览器指纹伪装才能稳定取数。"
|
||||
)
|
||||
categories = result.get(code, [])
|
||||
if not categories:
|
||||
return f"No concept/block data for {code}"
|
||||
|
||||
Reference in New Issue
Block a user