fix: extract author_username from <b> tags in postuserinfo div

This commit is contained in:
caibotmi 2026-04-05 16:33:29 +08:00
parent 9d418f3d8c
commit 4282eac809
1 changed files with 13 additions and 1 deletions

View File

@ -75,7 +75,7 @@ class YichensTodaySpider(PaginationSpider):
soup = BeautifulSoup(html, "html.parser")
page_text = soup.get_text()
match = re.search(r"ID=(\d+)", url)
match = re.search(r"\&ID=(\d+)", url)
post_id = match.group(1) if match else None
title = None
@ -135,6 +135,18 @@ class YichensTodaySpider(PaginationSpider):
elif "马钞" in title:
category = "马钞"
# 从 postuserinfo div 的 <b> 标签提取用户名(跳过电话号码)
if not author:
userinfos = soup.find_all('div', class_='postuserinfo')
for ui in userinfos:
for b in ui.find_all('b'):
text = b.get_text(strip=True)
if text and not re.match(r'^1\d{10}$', text) and len(text) > 1:
author = text
break
if author:
break
return {
"post_id": post_id,
"title": title,