解析账号
This commit is contained in:
+9
-24
@@ -544,30 +544,15 @@ def resolve_profile(payload: Dict[str, Any], token: Optional[str] = None):
|
|||||||
slow_mo = int(payload.get("slow_mo", 0))
|
slow_mo = int(payload.get("slow_mo", 0))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# 判断是否为小红书号(纯字母数字,不含空格和特殊字符)
|
# 统一使用搜索方式解析(按您的需求:搜索框输入 → 用户标签 → 获取URL)
|
||||||
import re
|
loghub.emit(f"[解析] 开始搜索解析:{keyword}")
|
||||||
is_xhs_id = bool(re.match(r'^[A-Za-z0-9]+$', keyword))
|
profile = resolve_profile_by_search(
|
||||||
|
keyword=keyword,
|
||||||
if is_xhs_id:
|
storage_state_path=storage_path,
|
||||||
# 对于小红书号,使用直接访问方式避免搜索跳转问题
|
headless=headless,
|
||||||
loghub.emit(f"[解析] 检测到小红书号格式,使用直接访问方式:{keyword}")
|
slow_mo=slow_mo,
|
||||||
profile = resolve_profile_by_direct_url(
|
log=loghub.emit,
|
||||||
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:
|
except Exception as e:
|
||||||
loghub.emit(f"[解析][错误] {e}")
|
loghub.emit(f"[解析][错误] {e}")
|
||||||
raise HTTPException(status_code=400, detail=str(e))
|
raise HTTPException(status_code=400, detail=str(e))
|
||||||
|
|||||||
+16
-4
@@ -618,23 +618,35 @@ def resolve_profile_by_search(
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
score = 0
|
score = 0
|
||||||
|
score_reasons = []
|
||||||
|
|
||||||
# 精确匹配小红书号:最高优先级
|
# 精确匹配小红书号:最高优先级
|
||||||
if xhs_no and xhs_no.lower() == kw.lower():
|
if xhs_no and xhs_no.lower() == kw.lower():
|
||||||
score += 1000
|
score += 1000
|
||||||
|
score_reasons.append("小红书号精确匹配")
|
||||||
|
|
||||||
# 精确匹配昵称:高优先级
|
# 精确匹配昵称:高优先级
|
||||||
elif nickname and nickname.lower() == kw.lower():
|
if nickname and nickname.lower() == kw.lower():
|
||||||
score += 500
|
score += 500
|
||||||
# 昵称包含关键词:中优先级
|
score_reasons.append("昵称精确匹配")
|
||||||
elif nickname and kw.lower() in nickname.lower():
|
|
||||||
|
# 昵称包含关键词:中优先级(不使用 elif,允许累加)
|
||||||
|
if nickname and kw.lower() in nickname.lower() and nickname.lower() != kw.lower():
|
||||||
score += 50
|
score += 50
|
||||||
|
score_reasons.append("昵称包含关键词")
|
||||||
|
|
||||||
# URL 中包含关键词:低优先级
|
# URL 中包含关键词:低优先级
|
||||||
if kw.lower() in href.lower():
|
if kw.lower() in href.lower():
|
||||||
score += 20
|
score += 20
|
||||||
|
score_reasons.append("URL包含关键词")
|
||||||
|
|
||||||
# 有有效的 profile ID:基础分
|
# 有有效的 profile ID:基础分
|
||||||
if _extract_profile_id_from_href(href):
|
if _extract_profile_id_from_href(href):
|
||||||
score += 5
|
score += 5
|
||||||
|
score_reasons.append("有效Profile ID")
|
||||||
|
|
||||||
_log(log, f"[账号] - 昵称: {nickname[:30] if len(nickname) > 30 else nickname}, 账号: {xhs_no}, 得分: {score}")
|
reasons_str = ", ".join(score_reasons) if score_reasons else "无匹配"
|
||||||
|
_log(log, f"[账号] - 昵称: {nickname[:30] if len(nickname) > 30 else nickname}, 账号: {xhs_no}, 得分: {score} ({reasons_str})")
|
||||||
|
|
||||||
if score > best_score:
|
if score > best_score:
|
||||||
best_score = score
|
best_score = score
|
||||||
|
|||||||
Reference in New Issue
Block a user