zhihu
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesezhihu — search, read & publish on Zhihu
zhihu — 知乎搜索、阅读与发布工具
Two authentication layers, two scripts:
| Script | Auth | Capabilities |
|---|---|---|
| | Search Zhihu, search the web, get hot topics |
| | Read/write own articles & answers |
No browser, no third-party deps — just .
urllibThe connector injects credentials as env vars:
- — Zhihu Developer Platform access secret (Bearer token). Used for search and hot-list queries. Secret — never echo or print it.
ZHIHU_DEVELOPER_TOKEN - — a JSON array of
ZHIHU_COOKIEScookies. Used for reading/writing the user's own content. Secret — never echo or print it.{name, value, domain, path, ...}
两层认证机制,对应两个脚本:
| 脚本 | 认证方式 | 功能 |
|---|---|---|
| | 搜索知乎、全网搜索、获取热榜 |
| | 读写个人文章与回答 |
无需浏览器,无第三方依赖——仅使用。
urllib连接器会将凭证注入为环境变量:
- —— 知乎开发者平台访问密钥(Bearer令牌)。用于搜索和热榜查询。保密内容——切勿回显或打印。
ZHIHU_DEVELOPER_TOKEN - —— 包含
ZHIHU_COOKIES的JSON数组Cookie。用于读写用户个人内容。保密内容——切勿回显或打印。{name, value, domain, path, ...}
Search CLI (search.py)
搜索CLI(search.py)
scripts/search.pyZHIHU_DEVELOPER_TOKENsh
SEARCH=$SKILL_DIR/scripts/search.pyscripts/search.pyZHIHU_DEVELOPER_TOKENsh
SEARCH=$SKILL_DIR/scripts/search.pySearch Zhihu content (站内搜索) — questions, answers, articles
搜索知乎站内内容(站内搜索)——问题、回答、文章
python3 $SEARCH search "Python 爬虫"
python3 $SEARCH search "Python 爬虫" --count 5
python3 $SEARCH search "Python 爬虫"
python3 $SEARCH search "Python 爬虫" --count 5
Search the entire web (全网搜索) — all indexed sites
全网搜索——所有已索引站点
python3 $SEARCH global "AI Agent"
python3 $SEARCH global "AI Agent" --count 15
python3 $SEARCH global "AI Agent"
python3 $SEARCH global "AI Agent" --count 15
Filter by site or time
按站点或时间筛选
python3 $SEARCH global "React" --filter 'host=="github.com"'
python3 $SEARCH global "新闻" --filter 'publish_time>=1720000000'
python3 $SEARCH global "技术" --filter 'host=="github.com" AND publish_time>=1720000000'
python3 $SEARCH global "实时新闻" --db realtime
python3 $SEARCH global "React" --filter 'host=="github.com"'
python3 $SEARCH global "新闻" --filter 'publish_time>=1720000000'
python3 $SEARCH global "技术" --filter 'host=="github.com" AND publish_time>=1720000000'
python3 $SEARCH global "实时新闻" --db realtime
Get Zhihu trending topics (热榜)
获取知乎热榜
python3 $SEARCH hot
python3 $SEARCH hot --limit 10
undefinedpython3 $SEARCH hot
python3 $SEARCH hot --limit 10
undefinedSearch commands
搜索命令
| Goal | Command |
|---|---|
| Search Zhihu (max 10 results) | |
| Search entire web (max 20) | |
| Filter by site | |
| Filter by time | |
| Search only realtime/static index | |
| Zhihu trending topics (max 30) | |
| 目标 | 命令 |
|---|---|
| 搜索知乎(最多10条结果) | |
| 全网搜索(最多20条结果) | |
| 按站点筛选 | |
| 按时间筛选 | |
| 仅搜索实时/静态索引 | |
| 知乎热榜(最多30条) | |
Search result fields
搜索结果字段
zhihu_search returns: title, type (Article/Answer), content_id, url,
excerpt, vote_up (赞同), comments, author, authority level, edit_time.
global_search returns the same fields plus has_more indicator. The
includes utm tracking params from Zhihu's platform.
urlhot_list returns: rank, title, url, summary, thumbnail.
zhihu_search 返回:标题、类型(文章/回答)、内容ID、链接、摘要、赞同数、评论数、作者、权威等级、编辑时间。
global_search 返回相同字段,外加是否还有更多结果的标识。包含知乎平台的utm跟踪参数。
urlhot_list 返回:排名、标题、链接、摘要、缩略图。
global_search Filter syntax
global_search 筛选语法
- — filter by domain (note:
host=="example.com"not supported — usehost=="zhihu.com"command instead)search - — filter by publish time (unix seconds)
publish_time>=1720000000 - Logical operators: ,
AND(must be uppercase)OR - Parentheses for grouping:
(host=="a.com" OR host=="b.com") AND publish_time>=T
- —— 按域名筛选(注意:不支持
host=="example.com"——请改用host=="zhihu.com"命令)search - —— 按发布时间筛选(Unix时间戳,单位秒)
publish_time>=1720000000 - 逻辑运算符:、
AND(必须大写)OR - 分组括号:
(host=="a.com" OR host=="b.com") AND publish_time>=T
Blog CLI (blog.py)
博客CLI(blog.py)
The skill ships — self-contained, stdlib only.
Requires (login cookie).
scripts/blog.pyZHIHU_COOKIESsh
BLOG=$SKILL_DIR/scripts/blog.py本工具附带——独立脚本,仅使用标准库。需要(登录Cookie)。
scripts/blog.pyZHIHU_COOKIESsh
BLOG=$SKILL_DIR/scripts/blog.pyRead (run directly)
读取操作(直接运行)
python3 $BLOG whoami # who is logged in
python3 $BLOG articles --limit 20 # my published articles + stats
python3 $BLOG article <article-id> # one article's details + stats
python3 $BLOG answers --limit 20 # my published answers + stats
python3 $BLOG answer <answer-id> # one answer's details + stats
python3 $BLOG question <question-id> # a question's info + whether I answered it
undefinedpython3 $BLOG whoami # 查询当前登录用户
python3 $BLOG articles --limit 20 # 查看个人已发布文章及数据
python3 $BLOG article <article-id> # 查看单篇文章详情及数据
python3 $BLOG answers --limit 20 # 查看个人已发布回答及数据
python3 $BLOG answer <answer-id> # 查看单条回答详情及数据
python3 $BLOG question <question-id> # 查看问题信息及是否已回答
undefinedVerify the connection first
先验证连接
sh
python3 $BLOG whoamish
python3 $BLOG whoami→ {"id": "...", "name": "崔庆才丨静觅", "url_token": "cui-qing-cai", ...}
→ {"id": "...", "name": "崔庆才丨静觅", "url_token": "cui-qing-cai", ...}
On a `401`/`403` the cookie is expired — tell the user to reconnect at
<https://auth.acedata.cloud/user/connections> (re-capture with the ACE
extension). Do **not** retry in a loop.
若返回`401`/`403`,说明Cookie已过期——告知用户前往<https://auth.acedata.cloud/user/connections>重新连接(通过ACE扩展重新捕获Cookie)。**切勿循环重试。**Reading recipes
读取操作示例
| Goal | Command |
|---|---|
| Who am I | |
| My latest articles + vote/comment counts | |
| My latest answers + like/favorite/comment counts | |
| Next page (any list) | add |
| One article's stats | |
| One answer's stats (incl. 赞同 voteup) | |
| A question's info + my answer id (if any) | |
Article stats: (赞同), (评论). Zhihu does not
expose per-article read counts on these endpoints.
voteup_countcomment_countAnswer stat caveat: the list endpoint does not return
(赞同) — it only exposes (喜欢),
(收藏) and . For the authoritative 赞同 count of an answer, call
(the single-answer endpoint returns ).
reports + so you know whether to use
(new) or (update).
answersvoteup_countlike_countfavorite_countcomment_countanswer <id>voteup_countquestion <id>already_answeredmy_answer_idanswer-questionedit-answer| 目标 | 命令 |
|---|---|
| 查询当前用户 | |
| 查看个人最新文章及赞同/评论数 | |
| 查看个人最新回答及喜欢/收藏/评论数 | |
| 查看下一页(任意列表) | 添加 |
| 查看单篇文章数据 | |
| 查看单条回答数据(含赞同数) | |
| 查看问题信息及个人回答ID(若已回答) | |
文章数据:(赞同)、(评论)。知乎在这些接口中不提供单篇文章的阅读量数据。
voteup_countcomment_count回答数据注意事项:列表接口不返回(赞同)——仅返回(喜欢)、(收藏)和。若要获取回答的权威赞同数,请调用(单条回答接口会返回)。会返回和,以便你判断应使用(新建回答)还是(更新回答)。
answersvoteup_countlike_countfavorite_countcomment_countanswer <id>voteup_countquestion <id>already_answeredmy_answer_idanswer-questionedit-answerPublishing — GATED (dry-run unless trailing --confirm
)
--confirm发布操作——受保护(无末尾--confirm
则为试运行)
--confirmpublish--confirm--confirm--confirmsh
undefinedpublish--confirm--confirm--confirmsh
undefinedContent is HTML. For Markdown, convert to HTML first (e.g. pandoc -f gfm -t html
).
pandoc -f gfm -t html内容为HTML格式。若为Markdown格式,请先转换为HTML(例如:pandoc -f gfm -t html
)。
pandoc -f gfm -t htmlpython3 $BLOG publish --title "标题" --content-file article.html # dry-run
python3 $BLOG publish --title "标题" --content-file article.html --draft-only --confirm # save a private draft
python3 $BLOG publish --title "标题" --content-file article.html --confirm # PUBLIC, goes live
- `--draft-only` stops after saving a private draft (safe — nothing public).
- Without `--draft-only`, the article is **published publicly** under the user's
name. Default to `--draft-only` unless the user clearly asked to go live.
- **Images are auto-hosted.** Zhihu strips any `<img>` whose `src` is not on its
own CDN, so on `--confirm` the CLI re-uploads every external image (HTML
`<img src>` **and** Markdown ``, plus `data:` URIs) to Zhihu's image
service and rewrites the URLs first — images already on `*.zhimg.com` are left
untouched. The result reports `images: {found, rehosted, failed}`; the dry-run
reports `images_found`. Pass `--no-images` to skip this. So you can hand the
CLI HTML/Markdown with normal public image URLs and the pictures survive.python3 $BLOG publish --title "标题" --content-file article.html # 试运行
python3 $BLOG publish --title "标题" --content-file article.html --draft-only --confirm # 保存为私有草稿
python3 $BLOG publish --title "标题" --content-file article.html --confirm # 公开发布
- `--draft-only`仅保存为私有草稿(安全操作——无公开内容)。
- 若无`--draft-only`,文章将以用户名义**公开发布**。除非用户明确要求立即发布,否则默认使用`--draft-only`。
- **图片自动托管**。知乎会移除所有`src`不在其自有CDN上的`<img>`标签,因此在执行`--confirm`时,CLI会将所有外部图片(HTML的`<img src>`、Markdown的``以及`data:` URI)重新上传至知乎图片服务,并重写URL——已在`*.zhimg.com`上的图片将保持不变。执行结果会返回`images: {found, rehosted, failed}`;试运行会返回`images_found`。可传入`--no-images`跳过此步骤。因此你可以直接向CLI传入包含普通公共图片URL的HTML/Markdown内容,图片会正常显示。Answering questions — GATED (dry-run unless trailing --confirm
)
--confirm回答问题操作——受保护(无末尾--confirm
则为试运行)
--confirmTwo write commands cover the question/answer side. Both gate exactly like
: no trailing → dry-run; is honored only
as the last argument. Always show the dry-run, get an explicit "yes", then
re-run with last.
publish--confirm--confirm--confirmsh
undefined两个写入命令用于处理问题与回答。两者的保护机制与完全相同:无末尾则为试运行;仅在作为最后一个参数时生效。请始终向用户展示试运行结果,获取明确的“确认”后,再添加作为最后一个参数重新运行。
publish--confirm--confirm--confirmsh
undefinedContent is HTML (same as articles). For Markdown, convert to HTML first.
内容为HTML格式(与文章要求相同)。若为Markdown格式,请先转换为HTML。
Post a NEW answer to a question
向问题发布新回答
python3 $BLOG answer-question --question <qid> --content-file ans.html # dry-run
python3 $BLOG answer-question --question <qid> --content-file ans.html --draft-only --confirm # PRIVATE draft (safe)
python3 $BLOG answer-question --question <qid> --content-file ans.html --confirm # PUBLIC, goes live
python3 $BLOG answer-question --question <qid> --content-file ans.html # 试运行
python3 $BLOG answer-question --question <qid> --content-file ans.html --draft-only --confirm # 保存为私有草稿(安全操作)
python3 $BLOG answer-question --question <qid> --content-file ans.html --confirm # 公开发布
Edit an EXISTING answer (replaces its live, public content)
编辑已有回答(替换其公开内容)
python3 $BLOG edit-answer --id <answer-id> --content-file ans.html # dry-run
python3 $BLOG edit-answer --id <answer-id> --content-file ans.html --confirm # overwrites live answer
- **One answer per question.** Zhihu allows a single answer per user per
question. If the user already answered, `answer-question --confirm` returns a
clear error telling you to use `edit-answer` instead — find the existing answer
id with `answers` or `question <qid>` (which reports `my_answer_id`).
- **`--draft-only` is the safe path for new answers** — it saves a *private*
draft on the question (nothing public). The user reviews it on Zhihu, then you
re-run without `--draft-only` (with `--confirm`) to publish. Prefer this unless
the user clearly asked to go live immediately.
- **`edit-answer` has no private mode** — the answer is already public, so any
`--confirm` edit is live immediately. It preserves the answer's current repost
setting unless you override with `--repost allowed|disallowed`.
- **转载授权** (`--repost allowed|disallowed`): new answers default to
`disallowed` (don't grant repost rights); editing keeps the current setting.
- **Images are auto-hosted** for answers too — same behavior and `--no-images`
flag as `publish`.python3 $BLOG edit-answer --id <answer-id> --content-file ans.html # 试运行
python3 $BLOG edit-answer --id <answer-id> --content-file ans.html --confirm # 覆盖公开回答
- **每个问题仅能回答一次**。知乎允许用户对每个问题仅回答一次。若用户已回答该问题,`answer-question --confirm`会返回明确错误,告知你应使用`edit-answer`——可通过`answers`或`question <qid>`(会返回`my_answer_id`)查找已有回答ID。
- **`--draft-only`是新建回答的安全路径**——它会在问题下保存一个私有草稿(无公开内容)。用户可在知乎上查看草稿,之后你可移除`--draft-only`(添加`--confirm`)重新运行以发布。除非用户明确要求立即发布,否则优先使用此方式。
- **`edit-answer`无私有模式**——回答已公开,因此任何`--confirm`编辑都会立即生效。除非你使用`--repost allowed|disallowed`覆盖设置,否则会保留回答当前的转载权限。
- **转载授权**(`--repost allowed|disallowed`):新建回答默认设置为`disallowed`(不授予转载权限);编辑回答时会保留当前设置。
- **回答中的图片也会自动托管**——与`publish`的行为相同,同样支持`--no-images`参数。Gotchas — surface before the user is surprised
注意事项——提前告知用户避免意外
- This is the user's real Zhihu account. Confirm before any publish / answer / edit; reading exposes their own private drafts.
- Cookie expiry: Zhihu cookies are short-lived. A /
401means reconnect at auth.acedata.cloud/user/connections — never loop-retry.403 - ToS: cookie automation is against most platforms' terms. This only ever acts on the user's own account with their own captured cookie; the user owns that risk. Never use it to scrape other people's content at scale.
- Never print — it is full account access.
ZHIHU_COOKIES - Scope: Zhihu only. Other Chinese platforms (掘金 / CSDN / …) ship as their
own per-platform skills (e.g. ,
csdn), each with its own connector — not ajuejinswitch here.--platform
- 操作的是用户真实知乎账号。在执行任何发布、回答或编辑操作前请确认;读取操作会暴露用户的私有草稿。
- Cookie过期:知乎Cookie有效期较短。返回/
401说明需前往auth.acedata.cloud/user/connections重新连接——切勿循环重试。403 - 服务条款:Cookie自动化违反多数平台的条款。本工具仅在用户自有账号上操作,使用用户自行捕获的Cookie;风险由用户自行承担。切勿用于大规模爬取他人内容。
- 切勿打印——它包含完整的账号访问权限。
ZHIHU_COOKIES - 适用范围:仅支持知乎。其他中文平台(掘金/CSDN/…)有各自独立的平台工具(如、
csdn),每个工具都有自己的连接器——本工具无juejin切换选项。--platform
Record the output
记录输出
After you successfully publish and obtain the live result URL, call the built-in
tool ONCE so the user can track this deliverable in My Outputs:
publish_artifactpublish_artifact(kind="article", channel="zhihu", title="<title>", url="<the REAL returned URL>", status="delivered")Use the real returned URL — never fabricate one. Call it once per published item,
only after delivery is confirmed; skip it (or use ) if publishing failed.
See .
status="failed"_shared/artifacts.md成功发布并获取真实结果链接后,调用内置的工具一次,以便用户在“我的输出”中跟踪此交付成果:
publish_artifactpublish_artifact(kind="article", channel="zhihu", title="<title>", url="<the REAL returned URL>", status="delivered")使用真实返回的链接——切勿伪造。每个发布项仅调用一次,仅在确认交付成功后调用;若发布失败则跳过(或使用)。详见。
status="failed"_shared/artifacts.md