Skip to main content

A CLI for Weibo (微博) — browse hot topics, search users, read timelines from the terminal

Project description

weibo-cli

CI PyPI version Python

A CLI for Weibo (微博) — browse hot topics, read timelines, and explore user profiles from the terminal 🐦

English | 中文

More Tools

  • twitter-cli — Twitter/X CLI for timelines, bookmarks, and posting
  • xiaohongshu-cli — Xiaohongshu (小红书) CLI for notes and account workflows
  • bilibili-cli — Bilibili CLI for videos, users, search, and feeds
  • discord-cli — Discord CLI for local-first sync, search, and export
  • tg-cli — Telegram CLI for local-first sync, search, and export

English

Features

Read:

  • Hot search: browse real-time trending topics and hashtags
  • Hot timeline: browse the trending feed
  • Search trends: real-time trending sidebar data
  • Weibo detail: view a weibo with full text, media, and stats
  • Comments: read comments on any weibo
  • User profiles: view user info, stats, and bio
  • User weibos: browse a user's published weibos
  • Following: view a user's following list
  • Structured output: export any data as JSON or YAML for scripting and AI agent integration

AI Agent Tip: Prefer --yaml for structured output unless strict JSON is required. Non-TTY stdout defaults to YAML automatically. Use --count to limit results.

Auth & Anti-Detection:

  • Cookie auth: auto-extract from Arc/Chrome/Edge/Firefox/Brave/Chromium/Opera/Vivaldi
  • QR code login: terminal-rendered QR code for Weibo App scan
  • Credential persistence: auto-save to ~/.config/weibo-cli/credential.json with 7-day TTL
  • Anti-detection: Chrome 145 User-Agent, Gaussian jitter, exponential backoff
  • Session auto-refresh: stale credentials trigger browser cookie re-extraction

Installation

# Recommended: uv tool (fast, isolated)
uv tool install kabi-weibo-cli

# Alternative: pipx
pipx install kabi-weibo-cli

Upgrade to the latest version:

uv tool upgrade kabi-weibo-cli

Install from source:

git clone git@github.com:jackwener/weibo-cli.git
cd weibo-cli
uv sync

Quick Start

# Login (auto-extract browser cookies or QR scan)
weibo login

# Browse hot search
weibo hot

# View hot timeline
weibo feed

# Check a weibo
weibo detail Qw06Kd98p

Usage

# ─── Auth ─────────────────────────────────────────
weibo login                            # Extract cookies from browser / QR login
weibo logout                           # Clear saved credentials
weibo status                           # Check login status
weibo me                               # Show current user profile

# ─── Hot & Trending ──────────────────────────────
weibo hot                              # Hot search list (50+ topics)
weibo hot --json                       # JSON output
weibo trending                         # Real-time search trends
weibo trending --yaml                  # YAML output

# ─── Feed ────────────────────────────────────────
weibo feed                             # Hot timeline
weibo feed --count 5                   # Limit results
weibo feed --json                      # JSON output

# ─── Weibo Detail ────────────────────────────────
weibo detail <mblogid>                 # View weibo with full stats
weibo detail Qw06Kd98p --json          # JSON output

# ─── Comments ────────────────────────────────────
weibo comments <mblogid>               # View comments
weibo comments Qw06Kd98p --count 10    # Limit count
weibo comments Qw06Kd98p --json        # JSON output

# ─── User ────────────────────────────────────────
weibo profile <uid>                    # User profile
weibo profile 1699432410 --json        # JSON output
weibo weibos <uid>                     # User's weibos
weibo weibos 1699432410 --count 5      # Limit count
weibo following <uid>                  # User's following list

Authentication

weibo-cli uses this auth priority:

  1. Saved credentials — loads from ~/.config/weibo-cli/credential.json
  2. Browser cookies (recommended) — auto-extract from Arc/Chrome/Edge/Firefox/Brave/Chromium/Opera/Vivaldi/Safari/LibreWolf
  3. QR code login — terminal QR code, scan with Weibo App

Browser extraction is recommended — it forwards ALL Weibo cookies and is closest to normal browser traffic.

Cookie TTL is 7 days by default. After expiry, the client automatically attempts browser re-extraction.

Troubleshooting

  • ⚠️ 未登录 — Run weibo login to authenticate
  • 会话已过期 — Cookie expired, run weibo logout && weibo login
  • Unable to get key for cookie decryption (macOS Keychain):
    • SSH sessions: security unlock-keychain ~/Library/Keychains/login.keychain-db
    • Local terminal: Open Keychain Access → search "Chrome Safe Storage"Access Control → add Terminal → Save
  • Requests are slow — intentional Gaussian jitter delay (~1s) to avoid triggering Weibo's risk control

Best Practices (Avoiding Bans)

  • Keep request volumes low — use --count 10 instead of --count 100
  • Don't run too frequently — the built-in rate limiter adds randomized delays
  • Use browser cookie extraction — provides full cookie fingerprint
  • Cookie values are stored locally and never uploaded

Output Modes

  • Default Rich table for interactive terminal reading
  • --json for scripts and agent pipelines
  • --yaml for structured output (auto-detected when stdout is not a TTY)

Development

# Install dev dependencies
uv sync --extra dev --extra yaml

# Lint + tests
uv run ruff check .
uv run pytest tests/ -v

# Smoke tests (require browser cookies)
uv run pytest tests/ -v -m smoke

Project Structure

weibo_cli/
├── __init__.py
├── cli.py             # Click entry point (12 commands)
├── client.py          # WeiboClient (14 API methods, rate-limit, retry)
├── auth.py            # QR login + browser-cookie3 + credential persistence
├── constants.py       # API endpoints, headers, Chrome 145 UA
├── exceptions.py      # WeiboApiError hierarchy (6 error types)
└── commands/
    ├── _common.py     # structured_output_options, handle_command
    ├── auth.py        # login/logout/status/me
    ├── search.py      # hot/feed/detail/comments/trending
    └── personal.py    # profile/weibos/following

Use as AI Agent Skill

weibo-cli ships with a SKILL.md so AI agents can execute common Weibo workflows.

Claude Code / Antigravity

mkdir -p .agents/skills
git clone git@github.com:jackwener/weibo-cli.git .agents/skills/weibo-cli

# Or copy SKILL.md only
curl -o .agents/skills/weibo-cli/SKILL.md \
  https://raw.githubusercontent.com/jackwener/weibo-cli/main/SKILL.md

OpenClaw / ClawHub

clawhub install weibo-cli

中文

功能特性

阅读:

  • 🔥 热搜:实时热门话题和标签
  • 📰 热门 Feed:热门时间线
  • 📈 搜索趋势:实时搜索趋势侧边栏
  • 📝 微博详情:查看完整正文、媒体和统计数据
  • 💬 评论:查看微博评论
  • 👤 用户资料:用户信息和统计
  • 📋 用户微博:浏览用户已发布的微博列表
  • 👥 关注列表:查看用户的关注列表
  • 📊 结构化输出:支持 JSON 和 YAML,便于脚本和 AI Agent 集成

AI Agent 提示: 需要结构化输出时优先使用 --yaml,除非下游必须是 JSON。stdout 不是 TTY 时默认输出 YAML。

认证与反风控:

  • Cookie 认证:支持 Arc/Chrome/Edge/Firefox/Brave 等 10+ 浏览器自动提取
  • 二维码登录:终端渲染二维码,用微博 APP 扫码
  • 凭证持久化:自动保存到 ~/.config/weibo-cli/credential.json,7 天 TTL
  • 反检测:Chrome 145 User-Agent、高斯抖动延迟、指数退避重试
  • 会话自动刷新:过期凭证自动触发浏览器 Cookie 重提取

安装

# 推荐:uv tool(快速、隔离环境)
uv tool install kabi-weibo-cli

# 或者:pipx
pipx install kabi-weibo-cli

升级到最新版本:

uv tool upgrade kabi-weibo-cli

从源码安装:

git clone git@github.com:jackwener/weibo-cli.git
cd weibo-cli
uv sync

使用示例

# 认证
weibo login                            # 从浏览器提取 Cookie / 二维码扫码
weibo logout                           # 清除已保存凭证
weibo status                           # 检查登录状态
weibo me                               # 查看当前用户信息

# 热搜
weibo hot                              # 热搜列表(50+ 条)
weibo hot --json                       # JSON 输出
weibo trending                         # 搜索趋势

# Feed
weibo feed                             # 热门时间线
weibo feed --count 5                   # 限制数量

# 微博详情与评论
weibo detail Qw06Kd98p                 # 查看微博
weibo comments Qw06Kd98p               # 查看评论

# 用户
weibo profile 1699432410               # 用户资料
weibo weibos 1699432410                # 用户微博列表
weibo following 1699432410             # 用户关注列表

常见问题

  • ⚠️ 未登录 — 执行 weibo login 认证
  • 会话已过期 — Cookie 过期,执行 weibo logout && weibo login
  • 请求较慢是正常的 — 内置高斯随机延迟(~1s)是为了模拟人类浏览行为,避免触发风控

作为 AI Agent Skill 使用

mkdir -p .agents/skills
git clone git@github.com:jackwener/weibo-cli.git .agents/skills/weibo-cli

License

Apache-2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kabi_weibo_cli-0.1.0.tar.gz (27.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kabi_weibo_cli-0.1.0-py3-none-any.whl (24.8 kB view details)

Uploaded Python 3

File details

Details for the file kabi_weibo_cli-0.1.0.tar.gz.

File metadata

  • Download URL: kabi_weibo_cli-0.1.0.tar.gz
  • Upload date:
  • Size: 27.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kabi_weibo_cli-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2f3f13884d64bb4b3f1cf4ecf92c6cdb5863df489fb589c47eb546b95df9f786
MD5 b1ed35934347d6aa1220e7cfedbcd56c
BLAKE2b-256 5410945dbf82839979686e70d719dc25b148ace17bee1deaa060dc835c640b3a

See more details on using hashes here.

Provenance

The following attestation bundles were made for kabi_weibo_cli-0.1.0.tar.gz:

Publisher: publish.yml on jackwener/weibo-cli

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kabi_weibo_cli-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: kabi_weibo_cli-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 24.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kabi_weibo_cli-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d2c425746791c72fd4e365b3147d11dc2949e1dafef48cf282de35ce33109ef6
MD5 292ecf17b7c7da044dc760604f50e40b
BLAKE2b-256 fac41b4a8808bd163f6008280e7c3f4415a45a028f6dd364a7111f65cbafcd0c

See more details on using hashes here.

Provenance

The following attestation bundles were made for kabi_weibo_cli-0.1.0-py3-none-any.whl:

Publisher: publish.yml on jackwener/weibo-cli

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page