From 21e0d8f393119225adbe61cd26d2434ab2dc51e5 Mon Sep 17 00:00:00 2001 From: Relakkes Date: Fri, 13 Sep 2024 16:01:34 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=9F=A5=E4=B9=8E?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E5=85=B3=E9=94=AE=E8=AF=8Dbug=EF=BC=8C?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E7=9A=84issue=20#435?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- media_platform/zhihu/core.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/media_platform/zhihu/core.py b/media_platform/zhihu/core.py index 2593133..6a3de2a 100644 --- a/media_platform/zhihu/core.py +++ b/media_platform/zhihu/core.py @@ -73,6 +73,12 @@ class ZhihuCrawler(AbstractCrawler): await login_obj.begin() await self.zhihu_client.update_cookies(browser_context=self.browser_context) + # 知乎的搜索接口需要打开搜索页面之后cookies才能访问API,单独的首页不行 + utils.logger.info("[ZhihuCrawler.start] Zhihu跳转到搜索页面获取搜索页面的Cookies,改过程需要5秒左右") + await self.context_page.goto(f"{self.index_url}/search?q=python&search_source=Guess&utm_content=search_hot&type=content") + await asyncio.sleep(5) + await self.zhihu_client.update_cookies(browser_context=self.browser_context) + crawler_type_var.set(config.CRAWLER_TYPE) if config.CRAWLER_TYPE == "search": # Search for notes and retrieve their comment information.