| name | weibo-hub |
| description | A skill for reading and writing Weibo data using Python + UV, powered by httpx. Cookies are auto-acquired via browser_use get_cookies for authentication โ no manual copying needed. Supports trending searches, hot feed, following feed, keyword search, weibo details/comments/reposts, user profiles/weibos/following/followers, etc. Trigger when user mentions "Weibo", "weibo", "weibo-hub", "Weibo trending", "scrape Weibo", "search Weibo", "Weibo comments", "Weibo users", or any scenario requiring programmatic access to Weibo data.
|
weibo-hub
Forked from: jackwener/weibo-cli (Apache-2.0)
This skill simplifies the original repo as follows:
- Removed
click / rich / browser-cookie3 / qrcode / pyyaml dependencies
- Retained only
httpx as a third-party dependency
- Removed CLI layer, all functionality packaged as sync Python API
- Auth changed to
browser_use get_cookies extract โ call setup_credential() to save
- Data directory changed to
/var/minis/workspace/weibo-hub/
File Structure
/var/minis/skills/weibo-hub/
โโโ SKILL.md
โโโ pyproject.toml # httpx only
โโโ scripts/
โโโ __init__.py
โโโ constants.py # API endpoints, Headers, path constants
โโโ exceptions.py # WeiboError exception hierarchy
โโโ auth.py # Credential persistence (no browser-cookie3)
โโโ client.py # WeiboClient core class (all APIs)
Authentication Flow (Check Before Each Use)
weibo-hub uses browser cookie authentication, extracted via browser_use get_cookies from weibo.com,
no browser-cookie3 needed, no QR scan required.
Step 1: Extract Cookies with browser_use
browser_use(action="navigate", url="https://weibo.com")
browser_use(action="get_cookies", url="https://weibo.com")
Step 2: Read from Env File and Save Credential
import sys, os, subprocess, json
env_file = "/var/minis/offloads/env_cookies_xxx.sh"
result = subprocess.run(
f". {env_file} && python3 -c \"import os,json; print(json.dumps(dict(os.environ)))\"",
shell=True, capture_output=True, text=True
)
env = json.loads(result.stdout)
cookies = {
k[len("COOKIE_"):]: v
for k, v in env.items()
if k.startswith("COOKIE_")
}
sys.path.insert(0, "/var/minis/skills/weibo-hub")
from scripts.client import WeiboClient
WeiboClient.setup_credential(cookies)
Key Cookies: SUB, SUBP (required), more is better.
Credential saved to /var/minis/workspace/weibo-hub/credential.json, valid for 7 days, auto-warns when expired.
Environment Setup
cd /var/minis/skills/weibo-hub
uv sync
Quick Start
import sys
sys.path.insert(0, "/var/minis/skills/weibo-hub")
from scripts.client import WeiboClient
with WeiboClient() as client:
topics = client.hot_search()
for t in topics[:10]:
print(f"#{t.get('realtime_hot_show_label','')} {t.get('word','')}")
band = client.hot_band()
trends = client.trending()
hot = client.hot_feed(count=10)
home = client.home_feed(count=20)
results = client.search("artificial intelligence", page=1)
for w in results[:5]:
print(w.get("text", "")[:80])
wb = client.detail("Qw06Kd98p")
cmt = client.comments("WeiboID", count=20)
rep = client.reposts("WeiboID", count=10)
me = client.me()
user = client.profile("1699432410")
weibos = client.user_weibos("1699432410", page=1)
following = client.following("1699432410", page=1)
followers = client.followers("1699432410", page=1)
API Reference
No Login Required (Public)
| Method | Description |
|---|
hot_search() | Trending sidebar (~52 items) |
hot_band() | Full trending list |
trending() | Real-time search suggestions |
hot_feed(count, max_id) | Hot timeline |
search(keyword, page) | Keyword search weibos |
Login Required (Cookie Auth)
| Method | Description |
|---|
me() | Current logged-in user info |
home_feed(count, max_id) | Following timeline |
detail(mblogid) | Single weibo detail |
comments(weibo_id, count, max_id) | Weibo comments list |
reposts(weibo_id, page, count) | Weibo reposts list |
profile(uid) | User profile |
user_weibos(uid, page, count) | User weibo list |
following(uid, page) | User following list |
followers(uid, page) | User followers list |
Auth
| Method | Description |
|---|
WeiboClient.setup_credential(cookies) | Save cookie credential (static method) |
Anti-Detection Notes
Consistent with upstream weibo-cli:
- Gaussian jitter: Each request interval =
request_delay + gauss(0.3, 0.15), ~1s
- 5% long pause: Random trigger of 2-5s extra delay, simulating reading behavior
- Exponential backoff: HTTP 429/5xx retry up to 3 times, wait 2^n seconds
- Chrome 145 UA: Desktop User-Agent, consistent with browser fingerprint
Notes
- First use must call
WeiboClient.setup_credential(cookies) to save credential
- Credential file:
/var/minis/workspace/weibo-hub/credential.json, permissions 0600
- Required Cookies:
SUB + SUBP, missing these will cause setup_credential() to raise ValueError
- Cookie auto-warns expiration after 7 days; re-extract required
- Trending/hot feed/search do not require login; profile/detail/home_feed require valid cookies
search() uses mobile API (m.weibo.cn), result format differs slightly