xianyu-goofish-cli
极简的闲鱼(Goofish)只读 CLI:扫码登录 → 搜索商品 → 会话列表 → IM 实时流。
许可证 Apache-2.0。仓库:https://git.weisanju.fun/weisanju/xianyu-cli。
实现上刻意避开了两件最麻烦的事:
- 不自己复刻 mtop 签名/风控:搜索时用 Patchright 打开真实 Chrome,监听页面自己发出的
mtop.taobao.idlemtopsearch.pc.search响应,直接解析 JSON。 - 不逆向 IM 私有二进制:闲鱼 WebSocket 实际是 LWP(JSON)协议,
wss://wss-goofish.dingtalk.com/, 本 CLI 只做注册、心跳、ack 和解码。
本项目是非官方实现,仅用于个人学习与低频只读场景。请遵守闲鱼用户协议;账号风控、封号等后果自负。
安装
pip install xianyu-goofish-cli
patchright install chrome # 或直接使用系统 Chrome(channel="chrome")
从源码:
git clone https://git.weisanju.fun/weisanju/xianyu-cli.git
cd xianyu-cli
python -m venv .venv
source .venv/bin/activate
pip install -e .
需要本机有 Chrome/Chromium。无桌面环境时用 xvfb-run 包一层。
使用
# 扫码登录:有头 Chrome 打开登录页,终端打印二维码,PNG 存在 ~/.xianyu-cli/qr.png
xianyu login
# 检查登录态
xianyu whoami
# 搜索(默认无头;被风控时加 --no-headless 或配合 xvfb-run)
xianyu search "iPad Pro" --limit 10
xianyu search "相机" --pages 2 --json
# 会话列表
xianyu chats --limit 50
xianyu chats --json
# 实时监听私信 60 秒
xianyu watch --seconds 60
xianyu watch --seconds 60 --json
全局 --json 可用于所有命令。
命令与退出码
| 命令 | 说明 |
|---|---|
login [--timeout N] [--no-headless] |
扫码登录,保存 cookie + storage_state |
whoami |
调用 loginuser.get 验证登录态 |
search <query> [--limit] [--pages] [--no-headless] |
拦截搜索响应并解析 |
chats [--limit] |
session.sync 拉会话列表 |
watch [--seconds] |
IM WebSocket 实时事件 |
退出码:0 成功,1 普通错误,2 未登录/登录失效,3 风控拦截,130 Ctrl-C。
数据位置
~/.xianyu-cli/
cookies.json # 登录 cookie(0600)
profile/ # 扫码登录用的 Chrome profile
storage_state.json
qr.png # 最近一次登录二维码
device.json # IM 设备 ID(按账号固定)
im_token.json # IM accessToken 缓存(30 分钟)
可用 XIANYU_HOME 改根目录。
发布(维护者)
PyPI 分发包名是 xianyu-goofish-cli(xianyu-cli 已被占用),导入包仍为 xianyu_cli,命令为 xianyu。
- 仓库 Settings → Actions → Secrets 添加
PYPI_API_TOKEN(PyPI API token,scope 建议只限本项目)。 - 改
pyproject.toml里的version,提交后打同名 tag:
git tag v0.1.0
git push origin v0.1.0
.forgejo/workflows/release.yml 会校验 tag 与版本一致、构建 sdist/wheel、跑 twine check,再上传 PyPI。
本地手动发布等价命令:
python -m pip install --upgrade build twine
python -m build
TWINE_USERNAME=__token__ TWINE_PASSWORD=pypi-... python -m twine upload dist/*
已知限制
- 只读:v1 不提供发消息、发布、自动回复。
search依赖页面实际发出搜索请求;未登录/登录失效时页面会弹登录框,CLI 会报“未捕获到搜索响应”。- 二维码 canvas 被中心 logo 跨域污染,不能
toDataURL(),本实现用元素截图。 - 会话列表来自
session.sync,可能与 App 端不完全一致。 - IM 协议随时可能变化;
watch目前只处理文本/图片/已读/新消息通知。 - 高频请求会触发
RGV587,CLI 会直接报错退出,不做自动重试风暴。
参考与致谢
协议常量与解析思路参考了以下 Apache-2.0 / MIT 项目:
- fancyboi999/goofish-cli(Apache-2.0):浏览器拦截搜索响应、LWP 注册/ack、
session.sync字段。 - cv-cat/XianYuApis(MIT):IM WebSocket 与 mtop 常量。
- superboyyy/xianyu_spider:IM 解码思路。
本项目为独立实现,未复制上述项目的完整代码;详见 NOTICE。
Metadata
Release files for xianyu-goofish-cli 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| xianyu_goofish_cli-0.1.0.tar.gz | 27.2 kB | Without provenance | Details for xianyu_goofish_cli-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| xianyu_goofish_cli-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for xianyu_goofish_cli-0.1.0-py3-none-any.whl |
Total release size: 53.6 kB
Release files / xianyu_goofish_cli-0.1.0.tar.gz
| Download URL | xianyu_goofish_cli-0.1.0.tar.gz |
|---|---|
| Size | 27.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
896163d08f5a2cc2961246224e6c4ef286b419fadcfaeb18dca37005f4a850b4
|
|
BLAKE2b-256 checksum How to use checksums |
df15d73cfce4df760f2f553b361cbda0b9c7fb7a4ad2a0582a01a280dc84aeb5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Release files / xianyu_goofish_cli-0.1.0-py3-none-any.whl
| Download URL | xianyu_goofish_cli-0.1.0-py3-none-any.whl |
|---|---|
| Size | 26.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7a15dd1a517edf4f984a19a1aef7f44cd4747c767c369191a025433cf7fef2f3
|
|
BLAKE2b-256 checksum How to use checksums |
b9f0306f59e56dffaed9cb6d704824d1f3de305205da6c307d253168077a6396
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Security for xianyu-goofish-cli 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.