Skip to content

Commit ca9b47e

Browse files
committed
fix: xhs 帖子详情优化
1 parent 43dffeb commit ca9b47e

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

media_platform/xhs/core.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,26 +273,25 @@ async def get_note_detail_async_task(
273273
note_detail_from_html, note_detail_from_api = None, None
274274
async with semaphore:
275275
try:
276-
# 尝试直接获取网页版笔记详情,不携带cookie
277-
note_detail_from_html: Dict = (
276+
# 尝试直接获取网页版笔记详情,携带cookie
277+
note_detail_from_html: Optional[Dict] = (
278278
await self.xhs_client.get_note_by_id_from_html(
279-
note_id, xsec_source, xsec_token, enable_cookie=False
279+
note_id, xsec_source, xsec_token, enable_cookie=True
280280
)
281281
)
282282
if not note_detail_from_html:
283-
# 如果网页版笔记详情获取失败,则尝试使用cookie获取
283+
# 如果网页版笔记详情获取失败,则尝试不使用cookie获取
284284
note_detail_from_html = (
285285
await self.xhs_client.get_note_by_id_from_html(
286-
note_id, xsec_source, xsec_token, enable_cookie=True
286+
note_id, xsec_source, xsec_token, enable_cookie=False
287287
)
288288
)
289289
utils.logger.error(
290290
f"[XiaoHongShuCrawler.get_note_detail_async_task] Get note detail error, note_id: {note_id}"
291291
)
292-
return None
293292
if not note_detail_from_html:
294293
# 如果网页版笔记详情获取失败,则尝试API获取
295-
note_detail_from_api: Dict = await self.xhs_client.get_note_by_id(
294+
note_detail_from_api: Optional[Dict] = await self.xhs_client.get_note_by_id(
296295
note_id, xsec_source, xsec_token
297296
)
298297
note_detail = note_detail_from_html or note_detail_from_api

0 commit comments

Comments
 (0)