fix: 修复知乎搜索关键词bug,相关的issue #435

This commit is contained in:
Relakkes 2024-09-13 16:01:34 +08:00
parent b1966478ba
commit 21e0d8f393
1 changed files with 6 additions and 0 deletions

View File

@ -73,6 +73,12 @@ class ZhihuCrawler(AbstractCrawler):
await login_obj.begin() await login_obj.begin()
await self.zhihu_client.update_cookies(browser_context=self.browser_context) 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) crawler_type_var.set(config.CRAWLER_TYPE)
if config.CRAWLER_TYPE == "search": if config.CRAWLER_TYPE == "search":
# Search for notes and retrieve their comment information. # Search for notes and retrieve their comment information.