browser-ai-cli 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Weiming
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,315 @@
1
+ Metadata-Version: 2.4
2
+ Name: browser-ai-cli
3
+ Version: 0.1.0
4
+ Summary: Multi-site AI aggregator CLI for Chinese AI products and search engines (Yuanbao, Kimi, Tongyi, Doubao, Baidu, Sogou WeChat, ...).
5
+ Author-email: Weiming3 <weiming3@users.noreply.github.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2026 Weiming
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+ Project-URL: Homepage, https://github.com/Weiming3/browser-ai
28
+ Project-URL: Issues, https://github.com/Weiming3/browser-ai/issues
29
+ Project-URL: Source code, https://github.com/Weiming3/browser-ai
30
+ Keywords: playwright,camoufox,browser-automation,ai-router,ai-aggregator,chinese-ai,wechat-search
31
+ Platform: any
32
+ Classifier: Development Status :: 4 - Beta
33
+ Classifier: Environment :: Console
34
+ Classifier: Intended Audience :: Developers
35
+ Classifier: License :: OSI Approved :: MIT License
36
+ Classifier: Operating System :: OS Independent
37
+ Classifier: Programming Language :: Python :: 3
38
+ Classifier: Programming Language :: Python :: 3.9
39
+ Classifier: Programming Language :: Python :: 3.10
40
+ Classifier: Programming Language :: Python :: 3.11
41
+ Classifier: Programming Language :: Python :: 3.12
42
+ Classifier: Programming Language :: Python :: 3.13
43
+ Classifier: Topic :: Internet :: WWW/HTTP :: Browsers
44
+ Classifier: Topic :: Utilities
45
+ Requires-Python: >=3.9
46
+ Description-Content-Type: text/markdown
47
+ License-File: LICENSE
48
+ Requires-Dist: playwright>=1.40.0
49
+ Requires-Dist: camoufox>=0.4.0
50
+ Dynamic: license-file
51
+
52
+ <p align="center">
53
+ <span>>简体中文<</span>
54
+ &nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
55
+ <a href="README_en.md" lang="en" hreflang="en">English</a>
56
+ </p>
57
+
58
+ # Browser-AI Toolkit / 浏览器 AI 工具集
59
+
60
+ <p align="center">
61
+ <img src="https://stone.professorlee.work/api/stone/Weiming3/browser-ai" alt="Stone Badge">
62
+ </p>
63
+
64
+ > 一个 CLI,把同一句话同时丢给一堆 AI 和搜索引擎,然后把答案排好序端回来。
65
+
66
+ [![Python](https://img.shields.io/badge/python-3.9%2B-blue)](https://www.python.org/)
67
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
68
+ [![Playwright](https://img.shields.io/badge/powered%20by-playwright-green)](https://playwright.dev/)
69
+
70
+ ---
71
+
72
+ ## 这是干嘛的?
73
+
74
+ `browser-ai` 是一个 Python CLI:把单条查询同时分发给多个 AI 服务(腾讯元宝、Kimi、通义千问、知乎直答、豆包……)和搜索引擎(百度、Google、搜狗微信),等所有源返回后做统一排序,输出一个综合结果。
75
+
76
+ 底层基于 Playwright,提供两个可按站点切换的引擎:
77
+
78
+ - **Chromium + 持久化 profile**:用于需要保留登录态的站点。
79
+ - **Camoufox**(反检测 Firefox):用于对普通浏览器进行指纹识别的搜索/抓取类站点。
80
+
81
+ 站点配置完全由 `config/ai_sites.json` 数据驱动。新增站点只需复制一段配置并修改选择器,**无需改动任何 Python 代码**。
82
+
83
+ ---
84
+
85
+ ## 和 OpenRouter / LiteLLM 有什么不同?
86
+
87
+ 看到这里第一反应很可能是「这不就是又一个 AI router 吗?」——问题合理,但**路由对象完全不同**。
88
+
89
+ | | OpenRouter / LiteLLM / OneAPI / Portkey | browser-ai |
90
+ |---|---|---|
91
+ | 路由对象 | LLM **API 端点** | AI **网页产品** + **搜索引擎网页** |
92
+ | 调用方式 | HTTP API(OpenAI 兼容格式) | 浏览器自动化(Playwright) |
93
+ | 鉴权 | API Key(按 token 计费) | 你自己的**登录态**(cookie / persistent profile) |
94
+ | 覆盖范围 | 有公开 API 的 LLM 提供商 | 有网页 UI 的一切——**包括没 API 的** |
95
+ | 输出 | 单个模型的文本回复 | 多源页面文本 + **统一打分排序** |
96
+ | 形态 | 后端服务 / 网关 | 本地 CLI |
97
+
98
+ API router 做不到的三件事,`browser-ai` 都覆盖:
99
+
100
+ **1. 那些「没 API、只有网页」的源。**
101
+
102
+ 腾讯元宝、知乎直答、Web 版豆包、B 站 AI 总结、搜狗微信——这些都没有公开 API,但都是有用信源。API router 物理上摸不到这一层。
103
+
104
+ **2. 主流 LLM 看不到的「围墙花园」内容。**
105
+
106
+ Gemini、GPT、Claude 这类模型有训练截止日期,而且语料重度偏向英文。它们对中文平台围墙内的内容覆盖非常弱:
107
+
108
+ - **微信公众号**:中文长文的主战场,Google 几乎索引不到,模型训练数据里也稀薄。
109
+ - **百度贴吧、知乎、小红书**:反爬严格、登录门槛高,西方爬虫根本看不见。
110
+ - **中文平台的实时内容**:上周刚发的帖子、新出的爆款文章,模型压根没见过。
111
+
112
+ `browser-ai` 通过搜狗微信(目前唯一的公开公众号聚合入口)、百度、加上你登录好的元宝 / Kimi 会话,**直接抓活的、带中文场景的真实资料**,而不是问一个 LLM 它几年前的记忆。`weixin` 命令就是为这个场景设计的——搜狗 + 百度 + 元宝三路包抄同一个查询,把 AI 看不到的中文长文搜回来,**给 LLM 的回答补充一个它够不着的思考维度**。
113
+
114
+ **3. AI + 搜索引擎混合扇出。**
115
+
116
+ 大多数 AI router 只在 LLM 之间扇出。`browser-ai` 把 AI 产品和搜索引擎(百度、Google、搜狗微信)混在同一次查询里——这是「边问 AI、边找参考资料」的唯一实用做法。
117
+
118
+ **一句话总结**:OpenRouter 做的是「**API 抽象层**」;`browser-ai` 做的是「**网页抽象层**」——把任何带网页的 AI 产品或搜索引擎,捏成一个统一查询目标。
119
+
120
+ ---
121
+
122
+ ## 和 `@playwright/mcp` 有什么不同?
123
+
124
+ > `@playwright/mcp` 是微软官方维护的 Playwright MCP 服务器:把浏览器自动化能力暴露成 MCP 工具,让 AI agent 可以一步步指挥浏览器。
125
+
126
+ 它和 `browser-ai` **不在同一个层面竞争**——一个把浏览器暴露给 AI,另一个是基于浏览器的预设工作流。
127
+
128
+ | | `@playwright/mcp` | browser-ai |
129
+ |---|---|---|
130
+ | 本质 | 通用浏览器遥控器(MCP 工具集) | 预设工作流 CLI |
131
+ | 决策者 | AI agent 自己(一步步操作) | JSON 配置(开箱即用) |
132
+ | 执行模式 | 单标签页串行 | 多站点并行扇出(`asyncio.gather`) |
133
+ | 站点知识 | 通用,每次让 AI 现场摸索 | 预配每个 AI 站点的选择器 / 等待逻辑 |
134
+ | 反检测 | 无 | `navigator.webdriver` 掩蔽 + 可选 Camoufox |
135
+ | 登录态 | 无 explicit 管理 | `config/profiles/` 按站点分目录 + Firefox cookie 导入 |
136
+ | 意图路由 | 无 | `search_routes.json` 按关键词决定探哪些站点 |
137
+ | 评分排序 | 无 | 三阶段 probe → evaluate → deep-dive |
138
+ | 公众号搜索 | 无 | `weixin` 命令三路包抄 |
139
+
140
+ **一句话总结**:
141
+
142
+ > `@playwright/mcp` 给 AI agent 一本**空白笔记本和一支笔**;`browser-ai` 是已经填好的**答题卡**,连笔迹都描过一遍了。
143
+
144
+ ### 推荐两者都装
145
+
146
+ 它们解决的问题不同,建议都装:
147
+
148
+ ```bash
149
+ # browser-ai:CLI 工作流(多源聚合、反检测、预配站点)
150
+ pip install playwright camoufox
151
+ playwright install chromium
152
+ camoufox fetch
153
+
154
+ # @playwright/mcp:MCP 工具集(让 Claude / Cursor / Cline 直接控制浏览器)
155
+ npm install -g @playwright/mcp
156
+ ```
157
+
158
+ - `@playwright/mcp` 适合「**让 AI 自由探索新站点**」的开放场景。
159
+ - `browser-ai` 适合「**中文 AI 产品聚合 + 围墙花园数据获取**」的预设场景。
160
+
161
+ 两个装上互不冲突,按场景切换用。
162
+
163
+ ---
164
+
165
+ ## 快速开始
166
+
167
+ ### 方式一:`pip install`(推荐给最终用户)
168
+
169
+ ```bash
170
+ pip install browser-ai-cli
171
+ playwright install chromium
172
+
173
+ # 可选:反检测场景用得到
174
+ camoufox fetch
175
+
176
+ # 首次运行会自动把模板配置拷到 ~/.config/browser-ai/config/
177
+ browser-ai-cli list
178
+
179
+ # 登录某个站点(会弹一个真的浏览器窗口,自己手动登录一下就行)
180
+ browser-ai-cli login yuanbao
181
+
182
+ # 全网智能搜索:AI + 搜索引擎一起上
183
+ browser-ai-cli search "python 异步编程最佳实践"
184
+
185
+ # 公众号文章:搜狗 + 百度 + 元宝三路包抄
186
+ browser-ai-cli weixin "微信公众号 跨境电商"
187
+ ```
188
+
189
+ > pip 安装模式下,配置和登录态落在 `~/.config/browser-ai/`(XDG 风格),和系统其他 dotfiles 一处管理。本地 checkout 模式下仍是仓库根目录的 `config/`,老用户行为不变。
190
+
191
+ ### 方式二:clone 仓库自己改(推荐给二次开发)
192
+
193
+ ```bash
194
+ git clone https://github.com/Weiming3/browser-ai.git
195
+ cd browser-ai
196
+ pip install -r requirements.txt
197
+ playwright install chromium
198
+
199
+ # 可选:装上 Camoufox,反检测场景用得到
200
+ pip install camoufox
201
+ camoufox fetch
202
+
203
+ # 把示例配置复制成你自己的本地配置
204
+ cp config/ai_sites.example.json config/ai_sites.json
205
+ cp config/search_routes.example.json config/search_routes.json
206
+
207
+ # 看看现在接了哪些站点
208
+ python scripts/browser_ai.py list
209
+
210
+ # 登录某个站点(会弹一个真的浏览器窗口,自己手动登录一下就行)
211
+ python scripts/browser_ai.py login yuanbao
212
+
213
+ # 全网智能搜索:AI + 搜索引擎一起上
214
+ python scripts/browser_ai.py search "python 异步编程最佳实践"
215
+
216
+ # 想单独戳某个源也行
217
+ python scripts/browser_ai.py probe "kimi 长文本"
218
+ ```
219
+
220
+ ---
221
+
222
+ ## 从 Firefox 导入已有登录态
223
+
224
+ 如果某些站点你已经在 Firefox 里登录过,不必再手动登录一次。`scripts/import_firefox_login.py` 会读取你本机 Firefox 的 `cookies.sqlite` 数据库,把对应的 cookie 写入到 `config/profiles/` 下对应的 Chromium profile 目录中。
225
+
226
+ ```bash
227
+ # 先 dry-run 看看会动哪些 cookie
228
+ python scripts/import_firefox_login.py --dry-run
229
+
230
+ # 确认无误后再真跑
231
+ python scripts/import_firefox_login.py
232
+
233
+ # 只导入某个站点的 cookie
234
+ python scripts/import_firefox_login.py --site yuanbao
235
+ ```
236
+
237
+ 强烈建议第一次使用先跑 `--dry-run` 预览。
238
+
239
+ ---
240
+
241
+ ## 目录结构
242
+
243
+ ```
244
+ browser-ai/
245
+ ├── scripts/
246
+ │ ├── browser_ai.py # 主 CLI
247
+ │ ├── import_firefox_login.py # Firefox 登录态搬运工
248
+ │ └── pre-commit-check.py # 提交前安全检查
249
+ ├── config/
250
+ │ ├── ai_sites.example.json # 模板,复制成 ai_sites.json
251
+ │ └── search_routes.example.json
252
+ ├── tests/
253
+ │ └── test_smoke.py # 26 个冒烟测试
254
+ ├── README.md
255
+ ├── README_en.md
256
+ ├── LICENSE
257
+ ├── pyproject.toml # pip 包元数据 + entry point
258
+ ├── requirements.txt
259
+ ├── .gitignore
260
+ └── .gitattributes
261
+ ```
262
+
263
+ ---
264
+
265
+ ## 加一个新 AI 站点
266
+
267
+ 最快是跑向导:
268
+
269
+ ```bash
270
+ python scripts/browser_ai.py add-site
271
+ ```
272
+
273
+ 愿意直接改 JSON 的话,从 `config/ai_sites.json` 里复制一段 site,改这几个字段就够了:`name`、`url`、`login_url`、`login_hint`、`selectors.input`、`selectors.submit`、`selectors.response`、`preferred_engine`。重启 CLI,新站点就上线了。
274
+
275
+ ---
276
+
277
+ ## 引擎怎么选?
278
+
279
+ | 引擎 | 适用场景 |
280
+ |------|----------|
281
+ | Chromium + profile | 需要登录态的站点(元宝、Kimi、豆包、B站)。 |
282
+ | Camoufox | 搜索/抓取类站点对无头 Chromium 不友好(百度、Google、搜狗微信)。 |
283
+
284
+ 在 `ai_sites.json` 里给每个站点设一个 `preferred_engine` 就完事,**只这一个开关**。两个引擎相互独立——想留就留,想拆就拆,反正不是承重墙。
285
+
286
+ ---
287
+
288
+ ## 真正要看两眼的就这两件事
289
+
290
+ **一、登录态别往仓库里塞。**
291
+
292
+ `config/profiles/` 里装的是 cookies、localStorage、IndexedDB,基本等同于每个站点的活动登录会话。`.gitignore` 默认已经把它排除在外了,**别动这一行**。真正的 `config/ai_sites.json` 也在 gitignore 里,模板是 `*.example.json` 那两份。仓库自带的 `scripts/pre-commit-check.py` 会拦下任何想偷偷把这俩文件加进去的 commit。建议这样用:
293
+
294
+ ```bash
295
+ python scripts/pre-commit-check.py # 每次提交前手动跑
296
+ cp scripts/pre-commit-check.py .git/hooks/pre-commit # 装成 git hook 自动拦截
297
+ ```
298
+
299
+ **二、站点的服务条款还是老大。**
300
+
301
+ 绝大多数 AI 平台的服务条款都明确禁止自动化访问。本工具就自己研究用,别拿去当爬虫服务赚钱,也别去薅别人的付费内容。被限流、被封 IP、被发律师函,都跟作者没关系,谢谢。
302
+
303
+ ---
304
+
305
+ ## 一些零碎
306
+
307
+ - `login` 和 `--headed` 一定弹窗,其他命令默认静默。
308
+ - 百度/Google 无头模式有时候会跳验证码,加 `--headed` 就行。
309
+ - 默认配置是样例,**不是真理**。按自己工作流改好再发给别人看。
310
+
311
+ ---
312
+
313
+ ## 许可证
314
+
315
+ MIT —— 见 [LICENSE](LICENSE)。
@@ -0,0 +1,264 @@
1
+ <p align="center">
2
+ <span>>简体中文<</span>
3
+ &nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
4
+ <a href="README_en.md" lang="en" hreflang="en">English</a>
5
+ </p>
6
+
7
+ # Browser-AI Toolkit / 浏览器 AI 工具集
8
+
9
+ <p align="center">
10
+ <img src="https://stone.professorlee.work/api/stone/Weiming3/browser-ai" alt="Stone Badge">
11
+ </p>
12
+
13
+ > 一个 CLI,把同一句话同时丢给一堆 AI 和搜索引擎,然后把答案排好序端回来。
14
+
15
+ [![Python](https://img.shields.io/badge/python-3.9%2B-blue)](https://www.python.org/)
16
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
17
+ [![Playwright](https://img.shields.io/badge/powered%20by-playwright-green)](https://playwright.dev/)
18
+
19
+ ---
20
+
21
+ ## 这是干嘛的?
22
+
23
+ `browser-ai` 是一个 Python CLI:把单条查询同时分发给多个 AI 服务(腾讯元宝、Kimi、通义千问、知乎直答、豆包……)和搜索引擎(百度、Google、搜狗微信),等所有源返回后做统一排序,输出一个综合结果。
24
+
25
+ 底层基于 Playwright,提供两个可按站点切换的引擎:
26
+
27
+ - **Chromium + 持久化 profile**:用于需要保留登录态的站点。
28
+ - **Camoufox**(反检测 Firefox):用于对普通浏览器进行指纹识别的搜索/抓取类站点。
29
+
30
+ 站点配置完全由 `config/ai_sites.json` 数据驱动。新增站点只需复制一段配置并修改选择器,**无需改动任何 Python 代码**。
31
+
32
+ ---
33
+
34
+ ## 和 OpenRouter / LiteLLM 有什么不同?
35
+
36
+ 看到这里第一反应很可能是「这不就是又一个 AI router 吗?」——问题合理,但**路由对象完全不同**。
37
+
38
+ | | OpenRouter / LiteLLM / OneAPI / Portkey | browser-ai |
39
+ |---|---|---|
40
+ | 路由对象 | LLM **API 端点** | AI **网页产品** + **搜索引擎网页** |
41
+ | 调用方式 | HTTP API(OpenAI 兼容格式) | 浏览器自动化(Playwright) |
42
+ | 鉴权 | API Key(按 token 计费) | 你自己的**登录态**(cookie / persistent profile) |
43
+ | 覆盖范围 | 有公开 API 的 LLM 提供商 | 有网页 UI 的一切——**包括没 API 的** |
44
+ | 输出 | 单个模型的文本回复 | 多源页面文本 + **统一打分排序** |
45
+ | 形态 | 后端服务 / 网关 | 本地 CLI |
46
+
47
+ API router 做不到的三件事,`browser-ai` 都覆盖:
48
+
49
+ **1. 那些「没 API、只有网页」的源。**
50
+
51
+ 腾讯元宝、知乎直答、Web 版豆包、B 站 AI 总结、搜狗微信——这些都没有公开 API,但都是有用信源。API router 物理上摸不到这一层。
52
+
53
+ **2. 主流 LLM 看不到的「围墙花园」内容。**
54
+
55
+ Gemini、GPT、Claude 这类模型有训练截止日期,而且语料重度偏向英文。它们对中文平台围墙内的内容覆盖非常弱:
56
+
57
+ - **微信公众号**:中文长文的主战场,Google 几乎索引不到,模型训练数据里也稀薄。
58
+ - **百度贴吧、知乎、小红书**:反爬严格、登录门槛高,西方爬虫根本看不见。
59
+ - **中文平台的实时内容**:上周刚发的帖子、新出的爆款文章,模型压根没见过。
60
+
61
+ `browser-ai` 通过搜狗微信(目前唯一的公开公众号聚合入口)、百度、加上你登录好的元宝 / Kimi 会话,**直接抓活的、带中文场景的真实资料**,而不是问一个 LLM 它几年前的记忆。`weixin` 命令就是为这个场景设计的——搜狗 + 百度 + 元宝三路包抄同一个查询,把 AI 看不到的中文长文搜回来,**给 LLM 的回答补充一个它够不着的思考维度**。
62
+
63
+ **3. AI + 搜索引擎混合扇出。**
64
+
65
+ 大多数 AI router 只在 LLM 之间扇出。`browser-ai` 把 AI 产品和搜索引擎(百度、Google、搜狗微信)混在同一次查询里——这是「边问 AI、边找参考资料」的唯一实用做法。
66
+
67
+ **一句话总结**:OpenRouter 做的是「**API 抽象层**」;`browser-ai` 做的是「**网页抽象层**」——把任何带网页的 AI 产品或搜索引擎,捏成一个统一查询目标。
68
+
69
+ ---
70
+
71
+ ## 和 `@playwright/mcp` 有什么不同?
72
+
73
+ > `@playwright/mcp` 是微软官方维护的 Playwright MCP 服务器:把浏览器自动化能力暴露成 MCP 工具,让 AI agent 可以一步步指挥浏览器。
74
+
75
+ 它和 `browser-ai` **不在同一个层面竞争**——一个把浏览器暴露给 AI,另一个是基于浏览器的预设工作流。
76
+
77
+ | | `@playwright/mcp` | browser-ai |
78
+ |---|---|---|
79
+ | 本质 | 通用浏览器遥控器(MCP 工具集) | 预设工作流 CLI |
80
+ | 决策者 | AI agent 自己(一步步操作) | JSON 配置(开箱即用) |
81
+ | 执行模式 | 单标签页串行 | 多站点并行扇出(`asyncio.gather`) |
82
+ | 站点知识 | 通用,每次让 AI 现场摸索 | 预配每个 AI 站点的选择器 / 等待逻辑 |
83
+ | 反检测 | 无 | `navigator.webdriver` 掩蔽 + 可选 Camoufox |
84
+ | 登录态 | 无 explicit 管理 | `config/profiles/` 按站点分目录 + Firefox cookie 导入 |
85
+ | 意图路由 | 无 | `search_routes.json` 按关键词决定探哪些站点 |
86
+ | 评分排序 | 无 | 三阶段 probe → evaluate → deep-dive |
87
+ | 公众号搜索 | 无 | `weixin` 命令三路包抄 |
88
+
89
+ **一句话总结**:
90
+
91
+ > `@playwright/mcp` 给 AI agent 一本**空白笔记本和一支笔**;`browser-ai` 是已经填好的**答题卡**,连笔迹都描过一遍了。
92
+
93
+ ### 推荐两者都装
94
+
95
+ 它们解决的问题不同,建议都装:
96
+
97
+ ```bash
98
+ # browser-ai:CLI 工作流(多源聚合、反检测、预配站点)
99
+ pip install playwright camoufox
100
+ playwright install chromium
101
+ camoufox fetch
102
+
103
+ # @playwright/mcp:MCP 工具集(让 Claude / Cursor / Cline 直接控制浏览器)
104
+ npm install -g @playwright/mcp
105
+ ```
106
+
107
+ - `@playwright/mcp` 适合「**让 AI 自由探索新站点**」的开放场景。
108
+ - `browser-ai` 适合「**中文 AI 产品聚合 + 围墙花园数据获取**」的预设场景。
109
+
110
+ 两个装上互不冲突,按场景切换用。
111
+
112
+ ---
113
+
114
+ ## 快速开始
115
+
116
+ ### 方式一:`pip install`(推荐给最终用户)
117
+
118
+ ```bash
119
+ pip install browser-ai-cli
120
+ playwright install chromium
121
+
122
+ # 可选:反检测场景用得到
123
+ camoufox fetch
124
+
125
+ # 首次运行会自动把模板配置拷到 ~/.config/browser-ai/config/
126
+ browser-ai-cli list
127
+
128
+ # 登录某个站点(会弹一个真的浏览器窗口,自己手动登录一下就行)
129
+ browser-ai-cli login yuanbao
130
+
131
+ # 全网智能搜索:AI + 搜索引擎一起上
132
+ browser-ai-cli search "python 异步编程最佳实践"
133
+
134
+ # 公众号文章:搜狗 + 百度 + 元宝三路包抄
135
+ browser-ai-cli weixin "微信公众号 跨境电商"
136
+ ```
137
+
138
+ > pip 安装模式下,配置和登录态落在 `~/.config/browser-ai/`(XDG 风格),和系统其他 dotfiles 一处管理。本地 checkout 模式下仍是仓库根目录的 `config/`,老用户行为不变。
139
+
140
+ ### 方式二:clone 仓库自己改(推荐给二次开发)
141
+
142
+ ```bash
143
+ git clone https://github.com/Weiming3/browser-ai.git
144
+ cd browser-ai
145
+ pip install -r requirements.txt
146
+ playwright install chromium
147
+
148
+ # 可选:装上 Camoufox,反检测场景用得到
149
+ pip install camoufox
150
+ camoufox fetch
151
+
152
+ # 把示例配置复制成你自己的本地配置
153
+ cp config/ai_sites.example.json config/ai_sites.json
154
+ cp config/search_routes.example.json config/search_routes.json
155
+
156
+ # 看看现在接了哪些站点
157
+ python scripts/browser_ai.py list
158
+
159
+ # 登录某个站点(会弹一个真的浏览器窗口,自己手动登录一下就行)
160
+ python scripts/browser_ai.py login yuanbao
161
+
162
+ # 全网智能搜索:AI + 搜索引擎一起上
163
+ python scripts/browser_ai.py search "python 异步编程最佳实践"
164
+
165
+ # 想单独戳某个源也行
166
+ python scripts/browser_ai.py probe "kimi 长文本"
167
+ ```
168
+
169
+ ---
170
+
171
+ ## 从 Firefox 导入已有登录态
172
+
173
+ 如果某些站点你已经在 Firefox 里登录过,不必再手动登录一次。`scripts/import_firefox_login.py` 会读取你本机 Firefox 的 `cookies.sqlite` 数据库,把对应的 cookie 写入到 `config/profiles/` 下对应的 Chromium profile 目录中。
174
+
175
+ ```bash
176
+ # 先 dry-run 看看会动哪些 cookie
177
+ python scripts/import_firefox_login.py --dry-run
178
+
179
+ # 确认无误后再真跑
180
+ python scripts/import_firefox_login.py
181
+
182
+ # 只导入某个站点的 cookie
183
+ python scripts/import_firefox_login.py --site yuanbao
184
+ ```
185
+
186
+ 强烈建议第一次使用先跑 `--dry-run` 预览。
187
+
188
+ ---
189
+
190
+ ## 目录结构
191
+
192
+ ```
193
+ browser-ai/
194
+ ├── scripts/
195
+ │ ├── browser_ai.py # 主 CLI
196
+ │ ├── import_firefox_login.py # Firefox 登录态搬运工
197
+ │ └── pre-commit-check.py # 提交前安全检查
198
+ ├── config/
199
+ │ ├── ai_sites.example.json # 模板,复制成 ai_sites.json
200
+ │ └── search_routes.example.json
201
+ ├── tests/
202
+ │ └── test_smoke.py # 26 个冒烟测试
203
+ ├── README.md
204
+ ├── README_en.md
205
+ ├── LICENSE
206
+ ├── pyproject.toml # pip 包元数据 + entry point
207
+ ├── requirements.txt
208
+ ├── .gitignore
209
+ └── .gitattributes
210
+ ```
211
+
212
+ ---
213
+
214
+ ## 加一个新 AI 站点
215
+
216
+ 最快是跑向导:
217
+
218
+ ```bash
219
+ python scripts/browser_ai.py add-site
220
+ ```
221
+
222
+ 愿意直接改 JSON 的话,从 `config/ai_sites.json` 里复制一段 site,改这几个字段就够了:`name`、`url`、`login_url`、`login_hint`、`selectors.input`、`selectors.submit`、`selectors.response`、`preferred_engine`。重启 CLI,新站点就上线了。
223
+
224
+ ---
225
+
226
+ ## 引擎怎么选?
227
+
228
+ | 引擎 | 适用场景 |
229
+ |------|----------|
230
+ | Chromium + profile | 需要登录态的站点(元宝、Kimi、豆包、B站)。 |
231
+ | Camoufox | 搜索/抓取类站点对无头 Chromium 不友好(百度、Google、搜狗微信)。 |
232
+
233
+ 在 `ai_sites.json` 里给每个站点设一个 `preferred_engine` 就完事,**只这一个开关**。两个引擎相互独立——想留就留,想拆就拆,反正不是承重墙。
234
+
235
+ ---
236
+
237
+ ## 真正要看两眼的就这两件事
238
+
239
+ **一、登录态别往仓库里塞。**
240
+
241
+ `config/profiles/` 里装的是 cookies、localStorage、IndexedDB,基本等同于每个站点的活动登录会话。`.gitignore` 默认已经把它排除在外了,**别动这一行**。真正的 `config/ai_sites.json` 也在 gitignore 里,模板是 `*.example.json` 那两份。仓库自带的 `scripts/pre-commit-check.py` 会拦下任何想偷偷把这俩文件加进去的 commit。建议这样用:
242
+
243
+ ```bash
244
+ python scripts/pre-commit-check.py # 每次提交前手动跑
245
+ cp scripts/pre-commit-check.py .git/hooks/pre-commit # 装成 git hook 自动拦截
246
+ ```
247
+
248
+ **二、站点的服务条款还是老大。**
249
+
250
+ 绝大多数 AI 平台的服务条款都明确禁止自动化访问。本工具就自己研究用,别拿去当爬虫服务赚钱,也别去薅别人的付费内容。被限流、被封 IP、被发律师函,都跟作者没关系,谢谢。
251
+
252
+ ---
253
+
254
+ ## 一些零碎
255
+
256
+ - `login` 和 `--headed` 一定弹窗,其他命令默认静默。
257
+ - 百度/Google 无头模式有时候会跳验证码,加 `--headed` 就行。
258
+ - 默认配置是样例,**不是真理**。按自己工作流改好再发给别人看。
259
+
260
+ ---
261
+
262
+ ## 许可证
263
+
264
+ MIT —— 见 [LICENSE](LICENSE)。