This commit is contained in:
mzl
2026-01-10 23:06:29 +08:00
parent dbe7617831
commit 59ef94c004
+24 -12
View File
@@ -576,35 +576,47 @@ def resolve_profile_by_search(
xhs_no = ""
try:
full_text = (it.inner_text() or "").strip()
# 解析昵称和小红书号
# 示例:青岛西门子家电规划师-海燕呀 1天前更新 小红书号:V13863940939 粉丝・52 笔记・217 关注
_log(log, f"[调试] 原始文本: {full_text[:100]}")
# 首先提取小红书号
m = re.search(r'小红书号[::]\s*([A-Za-z0-9]+)', full_text)
if m:
xhs_no = m.group(1).strip()
# 首先提取小红书号(尝试多种模式)
patterns = [
r'小红书号[::]\s*([A-Za-z0-9]+)',
r'小红书号[::]\s*([A-Za-z0-9]+)',
r'ID[::]\s*([A-Za-z0-9]+)',
r'账号[::]\s*([A-Za-z0-9]+)',
]
for pattern in patterns:
m = re.search(pattern, full_text)
if m:
xhs_no = m.group(1).strip()
_log(log, f"[调试] 匹配到小红书号: {xhs_no} (pattern: {pattern})")
break
if not xhs_no:
_log(log, f"[调试] 未能匹配小红书号")
# 提取昵称:从开头去除干扰信息
# 按行分割,通常第一行是昵称
lines = full_text.split('\n')
if lines:
# 取第一行作为主要文本
main_text = lines[0].strip()
_log(log, f"[调试] 第一行文本: {main_text}")
# 移除小红书号及其后面的所有内容
main_text = re.sub(r'小红书号[::].*$', '', main_text).strip()
# 移除时间信息(如 "1天前更新")
# 移除时间信息
main_text = re.sub(r'\s+\d+[天小时分秒]+前更新.*$', '', main_text).strip()
# 移除粉丝、笔记、关注信息
# 移除粉丝、笔记、关注
main_text = re.sub(r'\s+粉丝[・].*$', '', main_text).strip()
main_text = re.sub(r'\s+笔记[・].*$', '', main_text).strip()
main_text = re.sub(r'\s+关注.*$', '', main_text).strip()
# 移除分隔符
main_text = re.sub(r'\s*[・·]\s*', ' ', main_text).strip()
# 清理多余空格
nickname = re.sub(r'\s+', ' ', main_text).strip()
_log(log, f"[调试] 清理后昵称: {nickname}")
else:
nickname = full_text
except Exception:
except Exception as e:
_log(log, f"[调试] 解析异常: {e}")
nickname = ""
xhs_no = ""
else: