zhihu

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

zhihu — search, read & publish on Zhihu

zhihu — 知乎搜索、阅读与发布工具

Two authentication layers, two scripts:
ScriptAuthCapabilities
scripts/search.py
ZHIHU_DEVELOPER_TOKEN
(Bearer)
Search Zhihu, search the web, get hot topics
scripts/blog.py
ZHIHU_COOKIES
(login cookie)
Read/write own articles & answers
No browser, no third-party deps — just
urllib
.
The connector injects credentials as env vars:
  • ZHIHU_DEVELOPER_TOKEN
    — Zhihu Developer Platform access secret (Bearer token). Used for search and hot-list queries. Secret — never echo or print it.
  • ZHIHU_COOKIES
    — a JSON array of
    {name, value, domain, path, ...}
    cookies. Used for reading/writing the user's own content. Secret — never echo or print it.
两层认证机制,对应两个脚本:
脚本认证方式功能
scripts/search.py
ZHIHU_DEVELOPER_TOKEN
(Bearer令牌)
搜索知乎、全网搜索、获取热榜
scripts/blog.py
ZHIHU_COOKIES
(登录Cookie)
读写个人文章与回答
无需浏览器,无第三方依赖——仅使用
urllib
连接器会将凭证注入为环境变量:
  • ZHIHU_DEVELOPER_TOKEN
    —— 知乎开发者平台访问密钥(Bearer令牌)。用于搜索和热榜查询。保密内容——切勿回显或打印。
  • ZHIHU_COOKIES
    —— 包含
    {name, value, domain, path, ...}
    的JSON数组Cookie。用于读写用户个人内容。保密内容——切勿回显或打印。

Search CLI (search.py)

搜索CLI(search.py)

scripts/search.py
— search Zhihu and the web. Requires only
ZHIHU_DEVELOPER_TOKEN
(no cookies needed).
sh
SEARCH=$SKILL_DIR/scripts/search.py
scripts/search.py
—— 搜索知乎及全网内容。仅需
ZHIHU_DEVELOPER_TOKEN
(无需Cookie)。
sh
SEARCH=$SKILL_DIR/scripts/search.py

Search 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
undefined
python3 $SEARCH hot python3 $SEARCH hot --limit 10
undefined

Search commands

搜索命令

GoalCommand
Search Zhihu (max 10 results)
python3 $SEARCH search "<query>" --count N
Search entire web (max 20)
python3 $SEARCH global "<query>" --count N
Filter by site
--filter 'host=="example.com"'
Filter by time
--filter 'publish_time>=<unix_ts>'
Search only realtime/static index
--db realtime
or
--db static
Zhihu trending topics (max 30)
python3 $SEARCH hot --limit N
目标命令
搜索知乎(最多10条结果)
python3 $SEARCH search "<query>" --count N
全网搜索(最多20条结果)
python3 $SEARCH global "<query>" --count N
按站点筛选
--filter 'host=="example.com"'
按时间筛选
--filter 'publish_time>=<unix_ts>'
仅搜索实时/静态索引
--db realtime
--db static
知乎热榜(最多30条)
python3 $SEARCH hot --limit N

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
url
includes utm tracking params from Zhihu's platform.
hot_list returns: rank, title, url, summary, thumbnail.
zhihu_search 返回:标题、类型(文章/回答)、内容ID、链接、摘要、赞同数、评论数、作者、权威等级、编辑时间。
global_search 返回相同字段,外加是否还有更多结果的标识。
url
包含知乎平台的utm跟踪参数。
hot_list 返回:排名、标题、链接、摘要、缩略图。

global_search Filter syntax

global_search 筛选语法

  • host=="example.com"
    — filter by domain (note:
    host=="zhihu.com"
    not supported — use
    search
    command instead)
  • publish_time>=1720000000
    — filter by publish time (unix seconds)
  • Logical operators:
    AND
    ,
    OR
    (must be uppercase)
  • Parentheses for grouping:
    (host=="a.com" OR host=="b.com") AND publish_time>=T

  • host=="example.com"
    —— 按域名筛选(注意:不支持
    host=="zhihu.com"
    ——请改用
    search
    命令)
  • publish_time>=1720000000
    —— 按发布时间筛选(Unix时间戳,单位秒)
  • 逻辑运算符:
    AND
    OR
    (必须大写)
  • 分组括号:
    (host=="a.com" OR host=="b.com") AND publish_time>=T

Blog CLI (blog.py)

博客CLI(blog.py)

The skill ships
scripts/blog.py
— self-contained, stdlib only. Requires
ZHIHU_COOKIES
(login cookie).
sh
BLOG=$SKILL_DIR/scripts/blog.py
本工具附带
scripts/blog.py
——独立脚本,仅使用标准库。需要
ZHIHU_COOKIES
(登录Cookie)。
sh
BLOG=$SKILL_DIR/scripts/blog.py

Read (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
undefined
python3 $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> # 查看问题信息及是否已回答
undefined

Verify the connection first

先验证连接

sh
python3 $BLOG whoami
sh
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

读取操作示例

GoalCommand
Who am I
python3 $BLOG whoami
My latest articles + vote/comment counts
python3 $BLOG articles --limit 20
My latest answers + like/favorite/comment counts
python3 $BLOG answers --limit 20
Next page (any list)add
--offset 20
One article's stats
python3 $BLOG article <id>
One answer's stats (incl. 赞同 voteup)
python3 $BLOG answer <id>
A question's info + my answer id (if any)
python3 $BLOG question <id>
Article stats:
voteup_count
(赞同),
comment_count
(评论). Zhihu does not expose per-article read counts on these endpoints.
Answer stat caveat: the
answers
list endpoint does not return
voteup_count
(赞同) — it only exposes
like_count
(喜欢),
favorite_count
(收藏) and
comment_count
. For the authoritative 赞同 count of an answer, call
answer <id>
(the single-answer endpoint returns
voteup_count
).
question <id>
reports
already_answered
+
my_answer_id
so you know whether to use
answer-question
(new) or
edit-answer
(update).
目标命令
查询当前用户
python3 $BLOG whoami
查看个人最新文章及赞同/评论数
python3 $BLOG articles --limit 20
查看个人最新回答及喜欢/收藏/评论数
python3 $BLOG answers --limit 20
查看下一页(任意列表)添加
--offset 20
查看单篇文章数据
python3 $BLOG article <id>
查看单条回答数据(含赞同数)
python3 $BLOG answer <id>
查看问题信息及个人回答ID(若已回答)
python3 $BLOG question <id>
文章数据:
voteup_count
(赞同)、
comment_count
(评论)。知乎在这些接口中不提供单篇文章的阅读量数据。
回答数据注意事项
answers
列表接口不返回
voteup_count
(赞同)——仅返回
like_count
(喜欢)、
favorite_count
(收藏)和
comment_count
。若要获取回答的权威赞同数,请调用
answer <id>
(单条回答接口会返回
voteup_count
)。
question <id>
会返回
already_answered
my_answer_id
,以便你判断应使用
answer-question
(新建回答)还是
edit-answer
(更新回答)。

Publishing — GATED (dry-run unless trailing
--confirm
)

发布操作——受保护(无末尾
--confirm
则为试运行)

publish
writes to the user's real account. Without a trailing
--confirm
it dry-runs (prints what it would do, changes nothing).
--confirm
is honored only as the last argument, so a title/content containing "--confirm" can never silently go live. Always show the dry-run to the user, get an explicit "yes", then re-run with
--confirm
last.
sh
undefined
publish
会写入用户真实账号。若末尾无
--confirm
,则为试运行(仅打印执行内容,不做任何修改)。
--confirm
仅在作为最后一个参数时生效,因此标题/内容中包含"--confirm"的内容绝不会自动发布。请始终向用户展示试运行结果,获取明确的“确认”后,再添加
--confirm
作为最后一个参数重新运行。
sh
undefined

Content is HTML. For Markdown, convert to HTML first (e.g.
pandoc -f gfm -t html
).

内容为HTML格式。若为Markdown格式,请先转换为HTML(例如:
pandoc -f gfm -t html
)。

python3 $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 `![](url)`, 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的`![](url)`以及`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
则为试运行)

Two write commands cover the question/answer side. Both gate exactly like
publish
: no trailing
--confirm
dry-run;
--confirm
is honored only as the last argument. Always show the dry-run, get an explicit "yes", then re-run with
--confirm
last.
sh
undefined
两个写入命令用于处理问题与回答。两者的保护机制与
publish
完全相同:无末尾
--confirm
则为试运行
--confirm
仅在作为最后一个参数时生效。请始终向用户展示试运行结果,获取明确的“确认”后,再添加
--confirm
作为最后一个参数重新运行。
sh
undefined

Content 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
    401
    /
    403
    means reconnect at auth.acedata.cloud/user/connections — never loop-retry.
  • 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
    ZHIHU_COOKIES
    — it is full account access.
  • Scope: Zhihu only. Other Chinese platforms (掘金 / CSDN / …) ship as their own per-platform skills (e.g.
    csdn
    ,
    juejin
    ), each with its own connector — not a
    --platform
    switch here.
  • 操作的是用户真实知乎账号。在执行任何发布、回答或编辑操作前请确认;读取操作会暴露用户的私有草稿。
  • Cookie过期:知乎Cookie有效期较短。返回
    401
    /
    403
    说明需前往auth.acedata.cloud/user/connections重新连接——切勿循环重试。
  • 服务条款: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
publish_artifact
tool ONCE so the user can track this deliverable in My Outputs:
publish_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
status="failed"
) if publishing failed. See
_shared/artifacts.md
.
成功发布并获取真实结果链接后,调用内置的
publish_artifact
工具一次,以便用户在“我的输出”中跟踪此交付成果:
publish_artifact(kind="article", channel="zhihu", title="<title>", url="<the REAL returned URL>", status="delivered")
使用真实返回的链接——切勿伪造。每个发布项仅调用一次,仅在确认交付成功后调用;若发布失败则跳过(或使用
status="failed"
)。详见
_shared/artifacts.md