Skip to content

Commit

Permalink
fix: xhs 帖子详情优化
Browse files Browse the repository at this point in the history
  • Loading branch information
NanmiCoder committed Nov 27, 2024
1 parent 43dffeb commit ca9b47e
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions media_platform/xhs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,26 +273,25 @@ async def get_note_detail_async_task(
note_detail_from_html, note_detail_from_api = None, None
async with semaphore:
try:
# 尝试直接获取网页版笔记详情,不携带cookie
note_detail_from_html: Dict = (
# 尝试直接获取网页版笔记详情,携带cookie
note_detail_from_html: Optional[Dict] = (
await self.xhs_client.get_note_by_id_from_html(
note_id, xsec_source, xsec_token, enable_cookie=False
note_id, xsec_source, xsec_token, enable_cookie=True
)
)
if not note_detail_from_html:
# 如果网页版笔记详情获取失败,则尝试使用cookie获取
# 如果网页版笔记详情获取失败,则尝试不使用cookie获取
note_detail_from_html = (
await self.xhs_client.get_note_by_id_from_html(
note_id, xsec_source, xsec_token, enable_cookie=True
note_id, xsec_source, xsec_token, enable_cookie=False
)
)
utils.logger.error(
f"[XiaoHongShuCrawler.get_note_detail_async_task] Get note detail error, note_id: {note_id}"
)
return None
if not note_detail_from_html:
# 如果网页版笔记详情获取失败,则尝试API获取
note_detail_from_api: Dict = await self.xhs_client.get_note_by_id(
note_detail_from_api: Optional[Dict] = await self.xhs_client.get_note_by_id(
note_id, xsec_source, xsec_token
)
note_detail = note_detail_from_html or note_detail_from_api
Expand Down

1 comment on commit ca9b47e

@hezhenfan
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emm不太理解
为什么要试不带cookie的情况呢

Please sign in to comment.