fix(kuaishou): 支持网页端 REST 接口签名请求

- 新增页面签名环境捕获脚本,通过 caver 属性赋值轨迹获取签名调用入口
- 作品列表/关键词搜索接口迁移到带签名的 REST v2 请求,并显式校验 result 状态码
- 修复分页停止条件,空列表时结束翻页
- 更新默认创作者主页 ID
This commit is contained in:
程序员阿江(Relakkes)
2026-08-04 01:14:39 +08:00
parent 1779dde972
commit 2e558f1352
4 changed files with 152 additions and 11 deletions
+11 -6
View File
@@ -44,7 +44,11 @@ from var import comment_tasks_var, crawler_type_var, source_keyword_var
from .client import KuaiShouClient
from .exception import DataFetchError
from .help import parse_video_info_from_url, parse_creator_info_from_url
from .help import (
KS_SIGN_CAPTURE_SCRIPT,
parse_video_info_from_url,
parse_creator_info_from_url,
)
from .login import KuaishouLogin
@@ -94,6 +98,8 @@ class KuaishouCrawler(AbstractCrawler):
self.context_page = await self.browser_context.new_page()
# 注入快手签名环境捕获脚本,页面加载后即可通过 __ks_realm 生成 __NS_hxfalcon 签名
await self.context_page.add_init_script(KS_SIGN_CAPTURE_SCRIPT)
await self.context_page.goto(f"{self.index_url}?isHome=1")
# Create a client to interact with the kuaishou website.
@@ -151,7 +157,7 @@ class KuaishouCrawler(AbstractCrawler):
f"[KuaishouCrawler.search] search kuaishou keyword: {keyword}, page: {page}"
)
video_id_list: List[str] = []
videos_res = await self.ks_client.search_info_by_keyword(
videos_res = await self.ks_client.search_info_by_keyword_v2(
keyword=keyword,
pcursor=str(page),
search_session_id=search_session_id,
@@ -162,14 +168,13 @@ class KuaishouCrawler(AbstractCrawler):
)
break
vision_search_photo: Dict = videos_res.get("visionSearchPhoto")
if vision_search_photo.get("result") != 1:
if videos_res.get("result") != 1:
utils.logger.error(
f"[KuaishouCrawler.search] search info by keyword:{keyword} not found data "
)
break
search_session_id = vision_search_photo.get("searchSessionId", "")
for video_detail in vision_search_photo.get("feeds"):
search_session_id = videos_res.get("searchSessionId", "")
for video_detail in videos_res.get("feeds", []):
video_id_list.append(video_detail.get("photo", {}).get("id"))
await kuaishou_store.update_kuaishou_video(video_item=video_detail)