fix: extract author_username from <b> tags in postuserinfo div
This commit is contained in:
parent
9d418f3d8c
commit
4282eac809
|
|
@ -75,7 +75,7 @@ class YichensTodaySpider(PaginationSpider):
|
||||||
soup = BeautifulSoup(html, "html.parser")
|
soup = BeautifulSoup(html, "html.parser")
|
||||||
page_text = soup.get_text()
|
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
|
post_id = match.group(1) if match else None
|
||||||
|
|
||||||
title = None
|
title = None
|
||||||
|
|
@ -135,6 +135,18 @@ class YichensTodaySpider(PaginationSpider):
|
||||||
elif "马钞" in title:
|
elif "马钞" in title:
|
||||||
category = "马钞"
|
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 {
|
return {
|
||||||
"post_id": post_id,
|
"post_id": post_id,
|
||||||
"title": title,
|
"title": title,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue