Zhihu Cli

知乎 CLI (pyzhihu-cli):搜索、热榜、问题/回答、发想法/提问/文章、删自己的内容、点赞关注、通知。Agent 代执行 zhihu 命令,Cookie 仅存本地。

MIT-0 · Free to use, modify, and redistribute. No attribution required.
0 · 287 · 1 current installs · 1 all-time installs
byMei Zhihan@BAIGUANGMEI
MIT-0
Security Scan
VirusTotalVirusTotal
Benign
View report →
OpenClawOpenClaw
Benign
high confidence
Purpose & Capability
The name/description (zhihu CLI helper) matches the instructions: all actions are executed by running the installed `zhihu` CLI and optionally copying a QR image for OpenClaw to send. No unrelated credentials, binaries, or cloud access are requested.
Instruction Scope
The SKILL.md instructs the agent to access local paths (~/.zhihu-cli/* and the OpenClaw workspace media folder), run `zhihu` commands (including login with a pasted cookie), and use `openclaw message send` to deliver QR images. These are within the stated purpose but involve reading/writing local files and sending media externally; the doc explicitly prohibits uploading cookie contents, but using cookie-based login or an incorrect copy command could expose sensitive data if mishandled.
Install Mechanism
Instruction-only skill with no install spec or code to write to disk. Installation recommendations are standard package installs (uv/pipx/pip) and are sensible for a Python CLI.
Credentials
The skill declares no environment variables, no credentials, and no config paths beyond the local ~/.zhihu-cli cookies and OpenClaw workspace paths needed for QR delivery. Those local paths are proportionate to the task.
Persistence & Privilege
always is false and the skill does not request system-wide changes or persistent presence beyond using the local `zhihu` CLI and optionally OpenClaw workspace. The skill will run local commands when invoked (normal for an instruction-only CLI helper).
Assessment
This skill appears coherent for controlling a locally installed Zhihu CLI. Before installing/using it: 1) Do not paste your cookies into chat; prefer QR scan login. If you must use cookie-based login, paste it only into a secure terminal, not into conversations/logs. 2) Verify you trust the pyzhihu-cli package source before pip installing. 3) Be aware the agent will read/write files under ~/.zhihu-cli and may copy the QR image into the OpenClaw workspace media folder and invoke `openclaw message send` — ensure your OpenClaw messaging channels are configured only if you trust them. 4) If you are uncomfortable with an agent running local commands or with automatic QR forwarding, avoid enabling autonomous invocation or run commands manually yourself. 5) Monitor for any accidental exposure of cookies and use `zhihu logout` to revoke sessions if needed.

Like a lobster shell, security has layers — review code before you run it.

Current versionv0.2.5
Download zip
latestvk97acgrma446v4hdkp2cxnad2n830450

License

MIT-0
Free to use, modify, and redistribute. No attribution required.

SKILL.md

zhihu-cli 技能

前提

  • 已安装zhihu 在 PATH 中(uv tool install pyzhihu-cli / pipx install pyzhihu-cli / pip install pyzhihu-cli)。
  • 路径:配置与二维码路径 — Linux/macOS~/.zhihu-cli/(如 ~/.zhihu-cli/cookies.json~/.zhihu-cli/login_qrcode.png);Windows%USERPROFILE%\.zhihu-cli\(如 %USERPROFILE%\.zhihu-cli\cookies.json%USERPROFILE%\.zhihu-cli\login_qrcode.png)。
  • 配置:登录态存于上述 cookies.json不得将 Cookie 上传或写入对话/日志
  • 登录方式:仅两种 — 扫码 zhihu login --qrcode粘贴 Cookie zhihu login --cookie "z_c0=...; _xsrf=...; d_c0=..."
  • 扫码时:二维码会生成到上述路径的 login_qrcode.png。若用 OpenClaw 发给用户,须先复制到 OpenClaw 工作目录的 media 文件夹openclaw message send --media <media 路径>

Instruction Scope

本技能仅限:在用户本机调用已安装的 zhihu 命令,执行搜索、热榜、问题/回答、发想法/提问/文章、删除自己的内容、点赞关注、收藏与通知等操作;在用户请求扫码登录且已配置 OpenClaw 时,可将二维码图片经 OpenClaw 发送至用户指定渠道。不包含:代用户将 Cookie 上传至任何第三方、访问非知乎域名、或超出上述命令范围的操作。


Credentials

  • 知乎登录态:仅存于用户本机(Linux/macOS:~/.zhihu-cli/cookies.json;Windows:%USERPROFILE%\.zhihu-cli\cookies.json,权限 0600)。Agent 仅通过执行 zhihu 命令间接使用,不得将 Cookie 内容上传、转发或写入对话/日志
  • OpenClaw:若使用 openclaw message send 发送二维码,需用户自行配置 OpenClaw 及渠道凭证;本技能不声明、不持有该部分凭证。

安装与更新

  • 安装(任选其一):
    • uv tool install pyzhihu-cli
    • pipx install pyzhihu-cli
    • pip install pyzhihu-cli
  • 更新:按安装方式执行 uv tool upgrade pyzhihu-clipipx upgrade pyzhihu-clipip install -U pyzhihu-cli。用户问「升级/更新 zhihu」时提示其执行对应命令;不确定安装方式时可三种都给出。
  • 版本zhihu --version 查看当前版本。

Agent 规则

  1. 诉求 → 命令:按下表映射。
  2. 数据查询必须用 --json:凡执行数据查询类指令(如 searchhotquestionanswersansweruseruser-answersuser-articlesfeedtopiccollectionsnotificationswhoami 等),必须--json,以获取 API 返回的完整数据,便于解析、汇总或向用户展示;不得仅依赖终端表格等非结构化输出。
  3. 需登录时:先 zhihu status;未登录则 zhihu login --qrcode 或引导用户 zhihu login --cookie "..."
  4. 扫码登录:执行 zhihu login --qrcode 后,若本轮未发过二维码且用户已配置 OpenClaw → 先将二维码复制到 OpenClaw 工作目录的 media 文件夹,再 openclaw message send --channel <渠道> --target <目标> --media <media 路径>/login_qrcode.png --message "请用知乎 App 扫码并确认登录"保持登录进程不中断直到成功/失败/超时;用户说「重新登录/换号」则中断当前进程再重新执行登录。复制步骤:Linux/macOS:mkdir -p ~/.openclaw/workspace/media && cp ~/.zhihu-cli/login_qrcode.png ~/.openclaw/workspace/media/;Windows:mkdir "%USERPROFILE%\.openclaw\workspace\media" 2>nul & copy "%USERPROFILE%\.zhihu-cli\login_qrcode.png" "%USERPROFILE%\.openclaw\workspace\media\login_qrcode.png"(若 OpenClaw 工作目录不同则替换为实际路径)。
  5. 安全:Cookie 仅本地;优先扫码,避免在不可信处粘贴 Cookie;可提醒 zhihu logout 清空。
  6. 升级uv tool upgrade pyzhihu-cli / pipx upgrade pyzhihu-cli / pip install -U pyzhihu-cli

诉求 → 命令 速查

诉求命令
登录 / 扫码登录zhihu login --qrcode
Cookie 登录zhihu login --cookie "z_c0=...; _xsrf=...; d_c0=..."
重新登录 / 换号中断当前进程 → zhihu login --qrcode
检查登录zhihu status;看资料 zhihu whoami [--json]
搜索zhihu search "关键词" [--type general/topic/people] [--limit N] [--json]
热榜zhihu hot [--limit N] [--json]
问题zhihu question <id>;回答列表 zhihu answers <id> [--limit N]
回答详情zhihu answer <id> [--json]
用户zhihu user <url_token>user-answers / user-articles / followers / following
推荐 / 话题zhihu feedzhihu topic <id>
赞同zhihu vote <answer_id>;取消 zhihu vote --neutral <id>
关注问题zhihu follow-question <id>;取消 --unfollow
发提问zhihu ask "标题" [-d "描述"] [-t 话题id ...] [-i 图 ...]
发想法zhihu pin "标题" [-c "正文"] [-i 图 ...]
发文章zhihu article "标题" "正文" [-t 话题id ...] [-i 图 ...]
删提问/想法/文章zhihu delete-question <id> / delete-pin <id> / delete-article <id> [-y]
收藏 / 通知zhihu collectionszhihu notifications [-l N] [--offset M]
退出zhihu logout
版本 / 升级zhihu --version;升级见上规则 6

执行流程

用户诉求
  → 若「重新登录/换号」:中断当前 → zhihu login --qrcode → [发二维码] → 等完成
  → 否则:查上表得命令
    → 若该命令需登录:zhihu status → 未登录则 zhihu login --qrcode 或 --cookie
      → 若扫码且未发过图:复制到 media → openclaw message send --media ... → 保持进程
    → 执行 zhihu <子命令>(数据查询类必须带 --json)
    → 整理结果或报错提示

登录方式

方式命令
扫码zhihu login --qrcode:终端显示二维码并保存到本地(Linux/macOS:~/.zhihu-cli/login_qrcode.png;Windows:%USERPROFILE%\.zhihu-cli\login_qrcode.png);可经 OpenClaw 发图给用户。
手动 Cookiezhihu login --cookie "z_c0=...; _xsrf=...; d_c0=..."(浏览器 F12 → Network → 请求头 Cookie 复制)。

常用示例

zhihu login --qrcode
zhihu status
zhihu search "Python" --json
zhihu hot --limit 10
zhihu question 12345678
zhihu user someone
zhihu vote 87654321
zhihu pin "标题" -c "<p>正文</p>"
zhihu delete-pin 98765432 -y
zhihu notifications -l 10
zhihu logout

正文支持 HTML 富文本(ask-dpin-carticle 的正文)。


OpenClaw 发二维码(仅扫码时)

  1. 确保二维码已生成(Linux/macOS:~/.zhihu-cli/login_qrcode.png;Windows:%USERPROFILE%\.zhihu-cli\login_qrcode.png)。
  2. 复制到 OpenClaw 工作目录的 media 文件夹:
    • Linux/macOSmkdir -p ~/.openclaw/workspace/media && cp ~/.zhihu-cli/login_qrcode.png ~/.openclaw/workspace/media/
    • Windows(cmd)mkdir "%USERPROFILE%\.openclaw\workspace\media" 2>nul & copy "%USERPROFILE%\.zhihu-cli\login_qrcode.png" "%USERPROFILE%\.openclaw\workspace\media\login_qrcode.png"
    • Windows(PowerShell)New-Item -ItemType Directory -Force "$env:USERPROFILE\.openclaw\workspace\media" | Out-Null; Copy-Item "$env:USERPROFILE\.zhihu-cli\login_qrcode.png" "$env:USERPROFILE\.openclaw\workspace\media\login_qrcode.png" (若 OpenClaw 工作目录不是默认的 ~/.openclaw/workspace%USERPROFILE%\.openclaw\workspace,则替换为实际路径。)
  3. 发送:openclaw message send --channel <渠道> --target <目标> --media <工作目录>/media/login_qrcode.png --message "请用知乎 App 扫码并确认登录"(Linux/macOS 用 ~/.openclaw/workspace/media/login_qrcode.png,Windows 用 %USERPROFILE%\.openclaw\workspace\media\login_qrcode.png 或 PowerShell 中 $env:USERPROFILE\.openclaw\workspace\media\login_qrcode.png)。
  4. 不中断 zhihu login --qrcode 进程,等待用户完成。

错误处理

  • 未登录 / 401 / 403:先登录(zhihu login --qrcode--cookie),再执行原命令。
  • 超时 / 网络:提示重试或检查网络。
  • 其他:根据 CLI 报错给简短原因与建议(如检查 ID、url_token)。

Files

1 total
Select a file
Select a file to preview.

Comments

Loading comments…