From ca9b47ef63548d74a6e4487e6fcf458ab0b85342 Mon Sep 17 00:00:00 2001 From: Relakkes Date: Wed, 27 Nov 2024 09:41:24 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20xhs=20=E5=B8=96=E5=AD=90=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- media_platform/xhs/core.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/media_platform/xhs/core.py b/media_platform/xhs/core.py index 8a69086..88152b9 100644 --- a/media_platform/xhs/core.py +++ b/media_platform/xhs/core.py @@ -273,26 +273,25 @@ class XiaoHongShuCrawler(AbstractCrawler): 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