nashsu/AutoCLI

GitHub: nashsu/AutoCLI

一个用 Rust 编写的超快命令行工具,通过一条命令从 55+ 网站抓取数据并支持 AI 自动生成适配器。

Stars: 1943 | Forks: 173

# AutoCLI **[English](README.md) | [中文](README.zh.md) | [日本語](README.ja.md)**

autocli

https://autocli.ai — AI 驱动的适配器市场与云端 API

## 最新动态 ### v0.3.2 - **Chrome 扩展选择器工具** — 只需选择核心数据,从任意页面可视化选取元素,构建精确的 CSS 选择器以定位特定内容 - **通过 AutoCLI.ai 的 AI 驱动生成** — 根据您选择的数据,AI 自动扩展并发现相关字段,生成完整的抓取规则 - **无缝本地+云端同步** — 生成的适配器保存在本地并同步到 AutoCLI.ai,可立即使用 极快的命令行工具 — **一条命令获取任意网站信息**。支持 Twitter/X、Reddit、YouTube、HackerNews、Bilibili、知乎、小红书以及 [55+ 网站](#built-in-commands),同时支持控制 Electron 桌面应用、集成本地 CLI 工具(`gh`、`docker`、`kubectl`),由浏览器会话复用和 AI 原生发现能力驱动。 基于 [OpenCLI](> ~/.bashrc autocli completion zsh >> ~/.zshrc autocli completion fish > ~/.config/fish/completions/autocli.fish ``` ## AI 命令 ### 步骤 1:认证 ``` autocli auth ``` 这将: 1. 在浏览器中打开 [https://autocli.ai/get-token]( autocli

生成完成后,您可以使用新生成的命令通过 autocli 获取需要的数据。

autocli

### 步骤 3:搜索现有适配器 ``` # 按 URL 搜索 autocli search https://www.example.com # 域名也可以(自动添加 https://) autocli search example.com ``` 在 [autocli.ai](https://autocli.ai) 上搜索与 URL 匹配的社区共享适配器。从交互式列表中选择一个进行下载并本地保存 — 立即可用。 ### 环境变量 | 变量 | 描述 | 默认值 | |----------|-------------|---------| | `AUTOCLI_API_BASE` | 覆盖服务器 URL | `https://www.autocli.ai` | ## 内置命令 运行 `autocli --help` 查看所有可用命令。 | 网站 | 命令 | 模式 | |------|------|------| | **hackernews** | `top` `new` `best` `ask` `show` `jobs` `search` `user` | 公共 | | **devto** | `top` `tag` `user` | 公共 | | **lobsters** | `hot` `newest` `active` `tag` | 公共 | | **stackoverflow** | `hot` `search` `bounties` `unanswered` | 公共 | | **steam** | `top-sellers` | 公共 | | **linux-do** | `hot` `latest` `search` `categories` `category` `topic` | 公共 | | **arxiv** | `search` `paper` | 公共 | | **wikipedia** | `search` `summary` `random` `trending` | 公共 | | **apple-podcasts** | `search` `episodes` `top` 公共 | | **xiaoyuzhou** | `podcast` `podcast-episodes` `episode` | 公共 | | **bbc** | `news` | 公共 | | **hf** | `top` | 公共 | | **sinafinance** | `news` | 公共 | | **google** | `news` `search` `suggest` `trends` | 公共/浏览器 | | **v2ex** | `hot` `latest` `topic` `node` `user` `member` `replies` `nodes` `daily` `me` `notifications` | 公共/浏览器 | | **bloomberg** | `main` `markets` `economics` `industries` `tech` `politics` `businessweek` `opinions` `feeds` `news` | 公共/浏览器 | | **twitter** | `trending` `bookmarks` `profile` `search` `timeline` `thread` `following` `followers` `notifications` `post` `reply` `delete` `like` `article` `follow` `unfollow` `bookmark` `unbookmark` `download` `accept` `reply-dm` `block` `unblock` `hide-reply` | 浏览器 | | **bilibili** | `hot` `search` `me` `favorite` `history` `feed` `subtitle` `dynamic` `ranking` `following` `user-videos` `download` | 浏览器 | | **reddit** | `hot` `frontpage` `popular` `search` `subreddit` `read` `user` `user-posts` `user-comments` `upvote` `save` `comment` `subscribe` `saved` `upvoted` | 浏览器 | | **zhihu** | `hot` `search` `question` `download` | 浏览器 | | **xiaohongshu** | `search` `notifications` `feed` `user` `download` `publish` `creator-notes` `creator-note-detail` `creator-notes-summary` `creator-profile` `creator-stats` | 浏览器 | | **xueqiu** | `feed` `hot-stock` `hot` `search` `stock` `watchlist` `earnings-date` | 浏览器 | | **weibo** | `hot` `search` | 浏览器 | | **douban** | `search` `top250` `subject` `marks` `reviews` `movie-hot` `book-hot` | 浏览器 | | **weread** | `shelf` `search` `book` `highlights` `notes` `notebooks` `ranking` | 浏览器 | | **youtube** | `search` `video` `transcript` | 浏览器 | | **medium** | `feed` `search` `user` | 浏览器 | | **substack** | `feed` `search` `publication` | 浏览器 | | **sinablog** | `hot` `search` `article` `user` | 浏览器 | | **boss** | `search` `detail` `recommend` `joblist` `greet` `batchgreet` `send` `chatlist` `chatmsg` `invite` `mark` `exchange` `resume` `stats` | 浏览器 | | **jike** | `feed` `search` `create` `like` `comment` `repost` `notifications` `post` `topic` `user` | 浏览器 | | **facebook** | `feed` `profile` `search` `friends` `groups` `events` `notifications` `memories` `add-friend` `join-group` | 浏览器 | | **instagram** | `explore` `profile` `search` `user` `followers` `following` `follow` `unfollow` `like` `unlike` `comment` `save` `unsave` `saved` | 浏览器 | | **tiktok** | `explore` `search` `profile` `user` `following` `follow` `unfollow` `like` `unlike` `comment` `save` `unsave` `live` `notifications` `friends` | 浏览器 | | **yollomi** | `generate` `video` `edit` `upload` `models` `remove-bg` `upscale` `face-swap` `restore` `try-on` `background` `object-remover` | 浏览器 | | **yahoo-finance** | `quote` | 浏览器 | | **barchart** | `quote` `options` `greeks` `flow` | 浏览器 | | **linkedin** | `search` | 浏览器 | | **reuters** | `search` | 浏览器 | | **smzdm** | `search` | 浏览器 | | **ctrip** | `search` | 浏览器 | | **coupang** | `search` `add-to-cart` | 浏览器 | | **grok** | `ask` | 浏览器 | | **jimeng** | `generate` `history` | 浏览器 | | **chaoxing** | `assignments` `exams` | 浏览器 | | **weixin** | `download` | 浏览器 | | **doubao** | `status` `new` `send` `read` `ask` | 浏览器 | | **cursor** | `status` `send` `read` `new` `dump` `composer` `model` `extract-code` `ask` `screenshot` `history` `export` | 桌面 | | **codex** | `status` `send` `read` `new` `dump` `extract-diff` `model` `ask` `screenshot` `history` `export` | 桌面 | | **chatwise** | `status` `new` `send` `read` `ask` `model` `history` `export` `screenshot` | 桌面 | | **chatgpt** | `status` `new` `send` `read` `ask` | 桌面 | | **doubao-app** | `status` `new` `send` `read` `ask` `screenshot` `dump` | 桌面 | | **notion** | `status` `search` `read` `new` `write` `sidebar` `favorites` `export` | 桌面 | | **discord-app** | `status` `send` `read` `channels` `servers` `search` `members` | 桌面 | | **antigravity** | `status` `send` `read` `new` `dump` `extract-code` `model` `watch` | 桌面 | ## AI 发现能力 两种自动生成适配器的方式: ``` # 🤖 AI 驱动(推荐):LLM 分析页面并生成适配器 autocli generate https://www.example.com --goal hot --ai # 先在 autocli.ai 搜索现有适配器,如需要则用 AI 生成 # 🔧 基于规则:无需 AI 的启发式分析 autocli generate https://www.example.com --goal hot # 探索网站 API 表面(端点、框架、存储) autocli explore https://www.example.com --site mysite # 带交互式模糊测试(点击按钮触发隐藏 API) autocli explore https://www.example.com --auto --click "Comments,CC" # 自动检测认证策略(PUBLIC → COOKIE → HEADER) autocli cascade https://api.example.com/hot ``` **发现功能:** - `.json` 后缀探测(Reddit 风格的 REST 发现) - `__INITIAL_STATE__` 提取(SSR 网站如 Bilibili、小红书) - Pinia/Vuex store 发现和操作映射 - 自动搜索端点发现(`--goal search`) - 框架检测(Vue/React/Next.js/Nuxt) ## 下载 从支持的网站下载媒体和文章: ``` # 下载 Bilibili 视频(需要 yt-dlp) autocli bilibili download BV1xxx --output ./videos --quality 1080p # 下载知乎文章为 Markdown(带图片) autocli zhihu download "https://zhuanlan.zhihu.com/p/xxx" --output ./articles # 下载微信公众号文章为 Markdown(带图片) autocli weixin download "https://mp.weixin.qq.com/s/xxx" --output ./articles # 下载 Twitter/X 媒体(图片 + 视频) autocli twitter download nash_su --limit 10 --output ./twitter autocli twitter download --tweet-url "https://x.com/user/status/123" --output ./twitter ``` **下载功能:** - 通过 yt-dlp 下载视频(自动从浏览器提取 cookies,无需 Keychain 提示) - 文章保存为带 YAML 头信息的 Markdown(标题、作者、日期、来源) - 图片下载并本地化(远程 URL 替换为本地 `images/img_001.jpg`) - 输出目录结构:`output/article_title/title.md` + `output/article_title/images/` ## 外部 CLI 集成 集成的外部工具(透传执行): | 工具 | 描述 | |------|------| | `gh` | GitHub CLI | | `docker` | Docker CLI | | `kubectl` | Kubernetes CLI | | `obsidian` | Obsidian 笔记管理 | | `readwise` | Readwise 阅读管理 | | `gws` | Google Workspace CLI | ``` # Passthrough 到 GitHub CLI autocli gh repo list # Passthrough 到 kubectl autocli kubectl get pods ``` ## 输出格式 通过 `--format` 全局标志切换输出格式: ``` autocli hackernews top --format table # ASCII table (default) autocli hackernews top --format json # JSON autocli hackernews top --format yaml # YAML autocli hackernews top --format csv # CSV autocli hackernews top --format md # Markdown table ``` ## 认证策略 每个命令使用不同的认证策略: | 策略 | 描述 | 需要浏览器 | |------|------|--------------| | `public` | 公共 API,无需认证 | 否 | `cookie` | 需要浏览器 Cookie | 是 | | `header` | 需要特定请求头 | 是 | | `intercept` | 需要网络请求拦截 | 是 | | `ui` | 需要 UI 交互 | 是 | ## 自定义适配器 在 `~/.autocli/adapters/` 下创建 YAML 文件添加自定义适配器: ``` # ~/.autocli/adapters/mysite/hot.yaml site: mysite name: hot description: My site hot posts strategy: public browser: false args: limit: type: int default: 20 description: Number of items columns: [rank, title, score] pipeline: - fetch: https://api.mysite.com/hot - select: data.posts - map: rank: "${{ index + 1 }}" title: "${{ item.title }}" score: "${{ item.score }}" - limit: "${{ args.limit }}" ``` ### 流程步骤 | 步骤 | 功能 | 示例 | |------|------|------| | `fetch` | HTTP 请求 | `fetch: https://api.example.com/data` | | `evaluate` | 在浏览器中执行 JS | `evaluate: "document.title"` | | `navigate` | 页面导航 | `navigate: https://example.com` | | `click` | 点击元素 | `click: "#button"` | | `type` | 输入文本 | `type: { selector: "#input", text: "hello" }` | | `wait` | 等待 | `wait: 2000` | | `select` | 选择嵌套数据 | `select: data.items` | | `map` | 数据映射 | `map: { title: "${{ item.title }}" }` | | `filter` | 数据过滤 | `filter: "item.score > 10"` | | `sort` | 排序 | `sort: { by: score, order: desc }` | | `limit` | 截断 | `limit: "${{ args.limit }}"` | | `intercept` | 网络拦截 | `intercept: { pattern: "*/api/*" }` | | `tap` | 状态管理桥接 | `tap: { action: "store.fetch", url: "*/api/*" }` | | `download` | 下载 | `download: { type: media }` | ### 模板表达式 流程使用 `${{ expression }}` 语法: ``` # 变量访问 "${{ args.limit }}" "${{ item.title }}" "${{ index + 1 }}" # 比较和逻辑 "${{ item.score > 10 }}" "${{ item.title && !item.deleted }}" # 三元表达式 "${{ item.active ? 'yes' : 'no' }}" # 管道过滤器 "${{ item.title | truncate(30) }}" "${{ item.tags | join(', ') }}" "${{ item.name | lower | trim }}" # 字符串插值 "https://api.com/${{ item.id }}.json" # 回退 "${{ item.subtitle || 'N/A' }}" # 数学函数 "${{ Math.min(args.limit, 50) }}" ``` **内置过滤器(16 个):** `default`、`join`、`upper`、`lower`、`trim`、`truncate`、`replace`、`keys`、`length`、`first`、`last`、`json`、`slugify`、`sanitize`、`ext`、`basename` ## 配置 ### 环境变量 | 变量 | 默认值 | 描述 | |------|--------|------| | `OPENCLI_VERBOSE` | - | 启用详细输出 | | `OPENCLI_DAEMON_PORT` | `19825` | 守护进程端口 | | `OPENCLI_CDP_ENDPOINT` | - | CDP 直接端点(绕过守护进程) | | `OPENCLI_BROWSER_COMMAND_TIMEOUT` | `60` | 命令超时(秒) | | `OPENCLI_BROWSER_CONNECT_TIMEOUT` | `30` | 浏览器连接超时(秒) | | `OPENCLI_BROWSER_EXPLORE_TIMEOUT` | `120` | 发现超时(秒) | ### 文件路径 | 路径 | 描述 | |------|------| | `~/.autocli/adapters/` | 用户自定义适配器 | | `~/.autocli/plugins/` | 用户插件 | | `~/.autocli/external-clis.yaml` | 用户外部 CLI 注册表 | ## 架构 ``` ┌─────────────────────────────────────────────────────────────────┐ │ User / AI Agent │ │ autocli │ └─────────────────────┬───────────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────────────────────────────────┐ │ CLI Layer (clap) │ │ main.rs → discovery → clap dynamic subcommands → execution.rs │ │ ┌───────────┐ ┌───────────────┐ ┌──────────────────┐ │ │ │ Built-in │ │ Site adapter │ │ External CLI │ │ │ │ commands │ │ commands │ │ passthrough │ │ │ │ explore │ │ bilibili hot │ │ gh, docker, k8s │ │ │ │ doctor │ │ twitter feed │ │ │ │ │ └───────────┘ └───────┬───────┘ └──────────────────┘ │ └─────────────────────────┼───────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────────────────────────────────┐ │ Execution Engine (execution.rs) │ │ Arg validation → Capability routing → Timeout ctrl │ │ ┌─────────┼─────────┐ │ │ ▼ ▼ ▼ │ │ YAML Pipeline Rust Func External CLI │ └────────────────┬────────────────────────────────────────────────┘ │ ▼ ┌──────────────────────────────────────────────────────────────────┐ │ Pipeline Engine Browser Bridge │ │ ┌────────────┐ ┌─────────────────────┐ │ │ │ fetch │ │ BrowserBridge │ │ │ │ evaluate │ ──── IPage ────▶ │ DaemonClient (HTTP) │ │ │ │ navigate │ │ CdpPage (WebSocket) │ │ │ │ map/filter │ └──────────┬──────────┘ │ │ │ sort/limit │ │ │ │ │ intercept │ Daemon (axum:19825) │ │ │ tap │ HTTP + WebSocket │ │ └────────────┘ │ │ │ ▼ │ │ Expression Engine (pest) Chrome Extension (CDP) │ │ ${{ expr | filter }} chrome.debugger API │ └──────────────────────────────────────────────────────────────────┘ ``` ### 工作区结构 ``` autocli/ ├── crates/ │ ├── autocli-core/ # Core data models: Strategy, CliCommand, Registry, IPage trait, Error │ ├── autocli-pipeline/ # Pipeline engine: pest expressions, executor, 14 step types │ ├── autocli-browser/ # Browser bridge: Daemon, DaemonPage, CdpPage, DOM helpers │ ├── autocli-output/ # Output rendering: table, json, yaml, csv, markdown │ ├── autocli-discovery/ # Adapter discovery: YAML parsing, build.rs compile-time embedding │ ├── autocli-external/ # External CLI: loading, detection, passthrough execution │ ├── autocli-ai/ # AI capabilities: explore, synthesize, cascade, generate │ └── autocli-cli/ # CLI entry point: clap, execution orchestration, doctor, completion ├── adapters/ # 333 YAML adapter definitions │ ├── hackernews/ │ ├── bilibili/ │ ├── twitter/ │ └── ...(55 sites) └── resources/ └── external-clis.yaml # External CLI registry ``` ### 相对于 TypeScript 原版的改进 | 改进 | 原版(TypeScript) | autocli (Rust) | |--------|-------------------|-------------------| | 分发 | Node.js + npm install(~100MB) | 单个二进制文件(4.1MB) | | 启动速度 | 读取 manifest JSON → 解析 → 注册 | 编译时嵌入,零文件 I/O | | 模板引擎 | JS eval(安全风险) | pest PEG 解析器(类型安全) | | 并发获取 | 非浏览器模式 pool=5 | FuturesUnordered,concurrency=10 | | 错误系统 | 单一提示字符串 | 结构化错误链 + 多重建议 | | HTTP 连接 | 每次新建 fetch | reqwest 连接池复用 | | 内存安全 | GC | 所有权系统,零 GC 暂停 | ## 开发 ``` # 构建 cargo build # 测试(166 个测试) cargo test --workspace # 发布构建(带 LTO,约 4MB) cargo build --release # 添加新适配器 # 1. 在 adapters// 下创建 YAML 文件 # 2. 重新编译(build.rs 自动嵌入) cargo build ``` ## 支持的网站
点击展开全部 55 个网站 | 网站 | 命令 | 策略 | |------|--------|------| | hackernews | 8 | public | | bilibili | 12 | cookie | | twitter | 24 | cookie/intercept | | reddit | 15 | public/cookie | | zhihu | 2 | cookie | | xiaohongshu | 11 | cookie | | douban | 7 | cookie | | weibo | 2 | cookie | | v2ex | 11 | public/cookie | | bloomberg | 10 | cookie | | youtube | 4 | cookie | | wikipedia | 4 | public | | google | 4 | public/cookie | | facebook | 10 | cookie | | instagram | 14 | cookie | | tiktok | 15 | cookie | | notion | 8 | ui | | cursor | 12 | ui | | chatgpt | 6 | public | | stackoverflow | 4 | public | | devto | 3 | public | | lobsters | 4 | public | | medium | 3 | cookie | | substack | 3 | cookie | | weread | 7 | cookie | | xueqiu | 7 | cookie | | boss | 14 | cookie | | jike | 10 | cookie | | 其他 27 个网站 | ... | ... |
## Star 历史 Star History Chart ## 致谢 本项目基于 [jackwener](https://github.com/jackwener) 的 [OpenCLI](https://github.com/jackwener/opencli) 构建。我们衷心感谢使本项目成为可能的基础工作。 ## 许可证 Apache-2.0
标签:55+网站支持, BeEF, Electron, JSON 请求, Linux安全, Rust, 内存安全, 可视化界面, 命令控制, 多平台支持, 开发效率, 数据提取, 数据采集, 浏览器自动化, 爬虫, 网络可观测性, 网络数据获取, 网络流量审计, 网络调试, 自动化, 通知系统