Zhihu CLI
A CLI tool for interacting with Zhihu (知乎) content.
Installation
CODEBLOCK0
Commands
| Command | Description |
|---|
| INLINECODE0 | Auto-extract cookies from Chrome |
| INLINECODE1 |
Check login status |
|
zhihu set-cookie <cookie> | Set cookie manually |
|
zhihu hot | Get hot topics |
|
zhihu search <keyword> | Search content |
|
zhihu topics <keyword> | Search topics |
|
zhihu read <url> | Read answer/article |
|
zhihu user <token> | Get user info by url_token |
|
zhihu vote <url> | Browser Relay vote instructions |
|
zhihu follow [url] | Browser Relay follow instructions |
|
zhihu post | Browser Relay post instructions |
Features
- - 🔍 Search Zhihu content
- 🔥 Get hot topics
- 📖 Read answers/articles
- 👤 View user info
- 👍 Vote (via Browser Relay)
- 👣 Follow users (via Browser Relay)
- 🔐 Auto cookie extraction from Chrome
Cookie Setup
Option 1: Auto (recommended)
zhihu login
Opens Chrome and extracts cookies automatically.
Option 2: Manual
CODEBLOCK2
Browser Relay Operations
Some operations (vote, follow, post) require Browser Relay due to API limitations.
Setup
- 1. Ensure OpenClaw Browser Relay is connected
- Use the respective command to get instructions
Voting
zhihu vote <answer_url>
Then click the vote button in browser or use JS:
CODEBLOCK4
Following
zhihu follow <user_url>
Or click the follow button in browser.
API Limitations
Zhihu has restricted API access for:
- - Vote/unvote (use Browser Relay)
- Follow/unfollow (use Browser Relay)
- Comments (partially available)
Read operations (search, hot, read, user) work via API.
Examples
CODEBLOCK6
Notes
- - Cookie is stored in INLINECODE11
- Some features require login (votes, follows)
- Browser Relay provides more reliable write operations
Zhihu CLI
一个用于与知乎内容交互的命令行工具。
安装
bash
全局安装
npm install -g zhihu-cli
或使用 npx
npx zhihu-cli
命令
| 命令 | 描述 |
|---|
| zhihu login | 从 Chrome 自动提取 cookies |
| zhihu whoami |
检查登录状态 |
| zhihu set-cookie | 手动设置 cookie |
| zhihu hot | 获取热门话题 |
| zhihu search | 搜索内容 |
| zhihu topics | 搜索话题 |
| zhihu read | 阅读回答/文章 |
| zhihu user | 通过 url_token 获取用户信息 |
| zhihu vote | 浏览器中继投票说明 |
| zhihu follow [url] | 浏览器中继关注说明 |
| zhihu post | 浏览器中继发布说明 |
功能特性
- - 🔍 搜索知乎内容
- 🔥 获取热门话题
- 📖 阅读回答/文章
- 👤 查看用户信息
- 👍 投票(通过浏览器中继)
- 👣 关注用户(通过浏览器中继)
- 🔐 从 Chrome 自动提取 cookie
Cookie 设置
方式一:自动(推荐)
bash
zhihu login
打开 Chrome 并自动提取 cookies。
方式二:手动
bash
zhihu set-cookie 你的知乎cookie字符串
浏览器中继操作
由于 API 限制,某些操作(投票、关注、发布)需要通过浏览器中继完成。
设置
- 1. 确保已连接 OpenClaw 浏览器中继
- 使用相应命令获取操作说明
投票
bash
zhihu vote <回答链接>
然后在浏览器中点击投票按钮,或使用 JavaScript:
javascript
const btn = document.querySelector(button[class*=VoteButton]);
if (btn) btn.click();
关注
bash
zhihu follow <用户链接>
或在浏览器中点击关注按钮。
API 限制
知乎对以下 API 访问进行了限制:
- - 投票/取消投票(使用浏览器中继)
- 关注/取消关注(使用浏览器中继)
- 评论(部分可用)
读取操作(搜索、热门、阅读、用户)可通过 API 正常使用。
示例
bash
获取热门话题
zhihu hot
搜索 Python 教程
zhihu search Python教程
阅读回答
zhihu read https://www.zhihu.com/question/123456/answer/789012
获取用户信息
zhihu user lightislost
检查登录状态
zhihu whoami
注意事项
- - Cookie 存储在 ~/.zhihu-cookie
- 部分功能需要登录(投票、关注)
- 浏览器中继提供更可靠的写入操作