保护author为None但未被识别的情况

This commit is contained in:
crpa33 2025-03-27 23:22:47 +08:00 committed by GitHub
parent 6b6e2b8ba0
commit 3c72fc48b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -192,15 +192,18 @@ class ZhihuExtractor:
""" """
res = ZhihuCreator() res = ZhihuCreator()
if not author: try:
return res if not author:
if not author.get("id"): return res
author = author.get("member") if not author.get("id"):
res.user_id = author.get("id") author = author.get("member")
res.user_link = f"{zhihu_constant.ZHIHU_URL}/people/{author.get('url_token')}" res.user_id = author.get("id")
res.user_nickname = author.get("name") res.user_link = f"{zhihu_constant.ZHIHU_URL}/people/{author.get('url_token')}"
res.user_avatar = author.get("avatar_url") res.user_nickname = author.get("name")
res.url_token = author.get("url_token") res.user_avatar = author.get("avatar_url")
res.url_token = author.get("url_token")
finally:
pass
return res return res
def extract_comments(self, page_content: ZhihuContent, comments: List[Dict]) -> List[ZhihuComment]: def extract_comments(self, page_content: ZhihuContent, comments: List[Dict]) -> List[ZhihuComment]: