知乎 API 文档和测试仓库。
这个仓库把主项目里的知乎接口和 x-zse-96 签名方式独立出来,包含:
scripts/zhihu.raw.js: 知乎签名原始 JSscripts/zhihu_sign.js: 独立签名命令tests/zhihu_api_test.py: Python 测试客户端,通过 Node 调用签名 JSdocs/apis/*.md: 每个 API 一份 Markdown 文档.github/workflows/check.yml: 基础校验
- sign 生成 x-zse-96 签名
- recommend 推荐时间线
- following 关注时间线
- hot 热榜
- hot-questions 人气问题
- question-feeds 问题回答列表
- question-page 问题页面详情
- comments 回答根评论
- child-comments 子评论
- search 搜索
- vote-answer 回答投票
- follow-question 关注问题
- unfollow-question 取消关注问题
- read-items 上报已读
不要把 Cookie 写进仓库。测试脚本从环境变量读取:
$env:ZHIHU_COOKIE="你的知乎 Cookie"可参考 .env.example,但不要提交真实 Cookie。
签名接口需要 Cookie 里包含 d_c0。签名字符串格式:
101_3_3.0 + "+" + path_with_query + "+" + d_c0
cd APIS/zhihuapi
npm install
python -m pip install -r requirements.txt只测试签名 JS:
node scripts/zhihu_sign.js "101_3_3.0+/api/v3/feed/topstory/recommend?limit=10&desktop=true+你的d_c0"通过 Python 调 API:
python tests/zhihu_api_test.py sign
python tests/zhihu_api_test.py recommend
python tests/zhihu_api_test.py search --query "OpenAI"
python tests/zhihu_api_test.py hot-questions写入类接口默认 dry-run,必须显式加 --execute 才会真实调用:
python tests/zhihu_api_test.py vote-answer --answer-id 123 --type up --execute
python tests/zhihu_api_test.py follow-question --question-id 123 --execute