解析账号
This commit is contained in:
+26
-7
@@ -22,6 +22,7 @@ from xhs_crawler_core import (
|
||||
check_login_state_with_storage,
|
||||
login_mode_auto,
|
||||
resolve_profile_by_search,
|
||||
resolve_profile_by_direct_url,
|
||||
)
|
||||
|
||||
APP_ROOT = pathlib.Path(__file__).resolve().parent.parent
|
||||
@@ -541,14 +542,32 @@ def resolve_profile(payload: Dict[str, Any], token: Optional[str] = None):
|
||||
raise HTTPException(status_code=400, detail="keyword required")
|
||||
headless = bool(payload.get("headless", True))
|
||||
slow_mo = int(payload.get("slow_mo", 0))
|
||||
|
||||
try:
|
||||
profile = resolve_profile_by_search(
|
||||
keyword=keyword,
|
||||
storage_state_path=storage_path,
|
||||
headless=headless,
|
||||
slow_mo=slow_mo,
|
||||
log=loghub.emit,
|
||||
)
|
||||
# 判断是否为小红书号(纯字母数字,不含空格和特殊字符)
|
||||
import re
|
||||
is_xhs_id = bool(re.match(r'^[A-Za-z0-9]+$', keyword))
|
||||
|
||||
if is_xhs_id:
|
||||
# 对于小红书号,使用直接访问方式避免搜索跳转问题
|
||||
loghub.emit(f"[解析] 检测到小红书号格式,使用直接访问方式:{keyword}")
|
||||
profile = resolve_profile_by_direct_url(
|
||||
xhs_id=keyword,
|
||||
storage_state_path=storage_path,
|
||||
headless=headless,
|
||||
slow_mo=slow_mo,
|
||||
log=loghub.emit,
|
||||
)
|
||||
else:
|
||||
# 对于昵称或其他关键词,使用搜索方式
|
||||
loghub.emit(f"[解析] 使用搜索方式解析:{keyword}")
|
||||
profile = resolve_profile_by_search(
|
||||
keyword=keyword,
|
||||
storage_state_path=storage_path,
|
||||
headless=headless,
|
||||
slow_mo=slow_mo,
|
||||
log=loghub.emit,
|
||||
)
|
||||
except Exception as e:
|
||||
loghub.emit(f"[解析][错误] {e}")
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
|
||||
Reference in New Issue
Block a user