yuehua-ziniao-webdriver 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 Yuehua
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,438 @@
1
+ Metadata-Version: 2.4
2
+ Name: yuehua-ziniao-webdriver
3
+ Version: 0.1.0
4
+ Summary: 紫鸟浏览器自动化 Python SDK - 提供店铺管理、浏览器控制等功能
5
+ Author-email: Yuehua <shengxi_2000@outlook.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/yourusername/yuehua-ziniao-webdriver
8
+ Project-URL: Documentation, https://github.com/yourusername/yuehua-ziniao-webdriver#readme
9
+ Project-URL: Repository, https://github.com/yourusername/yuehua-ziniao-webdriver
10
+ Project-URL: Issues, https://github.com/yourusername/yuehua-ziniao-webdriver/issues
11
+ Keywords: ziniao,browser,automation,rpa,webdriver
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.8
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Operating System :: OS Independent
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Classifier: Topic :: Internet :: WWW/HTTP :: Browsers
24
+ Requires-Python: >=3.8
25
+ Description-Content-Type: text/markdown
26
+ License-File: LICENSE
27
+ Requires-Dist: DrissionPage>=4.0.0
28
+ Requires-Dist: requests>=2.28.0
29
+ Requires-Dist: typing-extensions>=4.5.0; python_version < "3.10"
30
+ Provides-Extra: dev
31
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
32
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
33
+ Requires-Dist: black>=23.0.0; extra == "dev"
34
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
35
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
36
+ Requires-Dist: build>=0.10.0; extra == "dev"
37
+ Requires-Dist: twine>=4.0.0; extra == "dev"
38
+ Dynamic: license-file
39
+
40
+ # 紫鸟浏览器 Python SDK
41
+
42
+ [![Python Version](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
43
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
44
+
45
+ 一个用于控制紫鸟浏览器的 Python SDK,提供店铺管理、浏览器自动化等功能。
46
+
47
+ ## ✨ 特性
48
+
49
+ - 🚀 **简单易用**:面向对象的 API 设计,清晰直观
50
+ - 🔄 **并发支持**:支持同时打开多个店铺,提高效率
51
+ - 🔍 **智能搜索**:通过店铺名称搜索,支持模糊匹配和精确匹配
52
+ - 🛡️ **类型安全**:完整的类型提示,IDE 友好
53
+ - ⚡ **自动重试**:内置重试机制,处理网络波动
54
+ - 📝 **日志系统**:集成 Python logging,方便调试
55
+ - 🎯 **错误处理**:清晰的异常体系,易于定位问题
56
+ - 🔌 **灵活配置**:支持代码、字典、文件等多种配置方式
57
+
58
+ ## 📦 安装
59
+
60
+ ### 从源码安装(开发中)
61
+
62
+ ```bash
63
+ # 克隆仓库
64
+ git clone https://github.com/yourusername/yuehua-ziniao-webdriver.git
65
+ cd yuehua-ziniao-webdriver
66
+
67
+ # 安装依赖
68
+ pip install -e .
69
+
70
+ # 安装开发依赖(可选)
71
+ pip install -e ".[dev]"
72
+ ```
73
+
74
+ ### 发布到 PyPI 后安装
75
+
76
+ ```bash
77
+ pip install yuehua-ziniao-webdriver
78
+ ```
79
+
80
+ ## 🚀 快速开始
81
+
82
+ ### 基本使用
83
+
84
+ ```python
85
+ from yuehua_ziniao_webdriver import ZiniaoClient, ZiniaoConfig
86
+
87
+ # 创建配置
88
+ config = ZiniaoConfig(
89
+ client_path=r"D:\ziniao\ziniao.exe", # 紫鸟客户端路径
90
+ company="你的企业名",
91
+ username="你的用户名",
92
+ password="你的密码",
93
+ version="v6" # v5 或 v6
94
+ )
95
+
96
+ # 使用上下文管理器(推荐)
97
+ with ZiniaoClient(config) as client:
98
+ # 获取店铺列表
99
+ stores = client.get_store_list()
100
+ print(f"共有 {len(stores)} 个店铺")
101
+
102
+ # 通过名称打开店铺
103
+ session = client.open_store_by_name("我的店铺")
104
+
105
+ # 检测 IP
106
+ if session.check_ip():
107
+ # 获取标签页进行操作
108
+ tab = session.get_tab()
109
+ tab.get("https://example.com")
110
+
111
+ # 关闭店铺
112
+ session.close()
113
+ ```
114
+
115
+ ### 并发打开多个店铺
116
+
117
+ ```python
118
+ from yuehua_ziniao_webdriver import ZiniaoClient, ZiniaoConfig
119
+
120
+ config = ZiniaoConfig(
121
+ client_path=r"D:\ziniao\ziniao.exe",
122
+ company="你的企业名",
123
+ username="你的用户名",
124
+ password="你的密码"
125
+ )
126
+
127
+ with ZiniaoClient(config) as client:
128
+ # 要打开的店铺名称列表
129
+ store_names = ["店铺A", "店铺B", "店铺C"]
130
+
131
+ # 并发打开(最多同时3个)
132
+ sessions = client.open_stores_by_names(
133
+ store_names,
134
+ max_workers=3
135
+ )
136
+
137
+ # 处理每个店铺
138
+ for store_name, session in sessions.items():
139
+ if session.check_ip():
140
+ tab = session.get_tab()
141
+ # 进行自动化操作
142
+ print(f"✓ {store_name} 已就绪")
143
+
144
+ # 关闭所有店铺
145
+ for session in sessions.values():
146
+ session.close()
147
+ ```
148
+
149
+ ## 📚 核心功能
150
+
151
+ ### 1. 客户端管理
152
+
153
+ ```python
154
+ from yuehua_ziniao_webdriver import ZiniaoClient, ZiniaoConfig
155
+
156
+ config = ZiniaoConfig(...)
157
+ client = ZiniaoClient(config)
158
+
159
+ # 启动客户端
160
+ client.start(
161
+ kill_existing=True, # 自动关闭已存在的进程
162
+ update_core=True # 启动后更新内核
163
+ )
164
+
165
+ # 检查客户端状态
166
+ if client.is_started():
167
+ print("客户端已启动")
168
+
169
+ # 关闭客户端
170
+ client.stop()
171
+ ```
172
+
173
+ ### 2. 店铺搜索
174
+
175
+ ```python
176
+ # 模糊搜索
177
+ stores = client.find_stores_by_name("亚马逊", exact_match=False)
178
+
179
+ # 精确搜索
180
+ stores = client.find_stores_by_name("我的亚马逊店铺", exact_match=True)
181
+
182
+ # 打印结果
183
+ for store in stores:
184
+ print(f"{store['browserName']} - {store['browserOauth']}")
185
+ ```
186
+
187
+ ### 3. 打开店铺
188
+
189
+ ```python
190
+ # 方式 1:通过 ID/OAuth
191
+ session = client.open_store("store_id_or_oauth")
192
+
193
+ # 方式 2:通过名称(推荐)
194
+ session = client.open_store_by_name("店铺名称")
195
+
196
+ # 方式 3:并发打开多个
197
+ sessions = client.open_stores_by_names(
198
+ ["店铺1", "店铺2", "店铺3"],
199
+ max_workers=3
200
+ )
201
+ ```
202
+
203
+ ### 4. 浏览器操作
204
+
205
+ ```python
206
+ # 打开店铺
207
+ session = client.open_store_by_name("我的店铺")
208
+
209
+ # 检测 IP
210
+ if session.check_ip(timeout=60):
211
+ print("IP 检测通过")
212
+
213
+ # 打开启动页面
214
+ session.open_launcher_page()
215
+
216
+ # 获取标签页
217
+ tab = session.get_tab()
218
+
219
+ # 导航到 URL
220
+ session.navigate("https://example.com", wait_time=2)
221
+
222
+ # 关闭会话
223
+ session.close()
224
+ ```
225
+
226
+ ### 5. 配置管理
227
+
228
+ ```python
229
+ from yuehua_ziniao_webdriver import ZiniaoConfig
230
+
231
+ # 方式 1:代码配置
232
+ config = ZiniaoConfig(
233
+ client_path=r"D:\ziniao\ziniao.exe",
234
+ company="企业名",
235
+ username="用户名",
236
+ password="密码"
237
+ )
238
+
239
+ # 方式 2:从字典
240
+ config = ZiniaoConfig.from_dict({
241
+ "client_path": r"D:\ziniao\ziniao.exe",
242
+ "company": "企业名",
243
+ "username": "用户名",
244
+ "password": "密码"
245
+ })
246
+
247
+ # 方式 3:从 JSON 文件
248
+ config = ZiniaoConfig.from_json_file("config.json")
249
+
250
+ # 方式 4:从环境变量
251
+ config = ZiniaoConfig.from_env(prefix="ZINIAO_")
252
+
253
+ # 保存配置到文件
254
+ config.to_json_file("config.json")
255
+ ```
256
+
257
+ ### 6. 错误处理
258
+
259
+ ```python
260
+ from yuehua_ziniao_webdriver import (
261
+ StoreNotFoundError,
262
+ MultipleStoresFoundError,
263
+ StoreOperationError
264
+ )
265
+
266
+ try:
267
+ session = client.open_store_by_name("店铺名称")
268
+
269
+ except StoreNotFoundError as e:
270
+ print(f"未找到店铺:{e.store_identifier}")
271
+
272
+ except MultipleStoresFoundError as e:
273
+ print(f"找到多个匹配的店铺:{e.store_names}")
274
+
275
+ except StoreOperationError as e:
276
+ print(f"操作失败:{e.message}")
277
+ ```
278
+
279
+ ### 7. 日志配置
280
+
281
+ ```python
282
+ from yuehua_ziniao_webdriver import setup_logging
283
+ import logging
284
+
285
+ # 配置日志
286
+ setup_logging(
287
+ level=logging.INFO,
288
+ log_file="ziniao.log" # 可选:输出到文件
289
+ )
290
+ ```
291
+
292
+ ## 🔧 配置参数
293
+
294
+ | 参数 | 类型 | 必需 | 默认值 | 说明 |
295
+ |------|------|------|--------|------|
296
+ | `client_path` | `str` | ✅ | - | 紫鸟客户端可执行文件路径 |
297
+ | `company` | `str` | ✅ | - | 企业名称(登录用) |
298
+ | `username` | `str` | ✅ | - | 用户名(登录用) |
299
+ | `password` | `str` | ✅ | - | 密码(登录用) |
300
+ | `socket_port` | `int` | ❌ | `16851` | 通信端口 |
301
+ | `version` | `"v5" \| "v6"` | ❌ | `"v6"` | 客户端版本 |
302
+ | `request_timeout` | `int` | ❌ | `120` | 请求超时时间(秒) |
303
+ | `max_retries` | `int` | ❌ | `3` | 最大重试次数 |
304
+ | `retry_delay` | `float` | ❌ | `2.0` | 重试延迟(秒) |
305
+
306
+ ## 📖 API 文档
307
+
308
+ ### ZiniaoClient
309
+
310
+ 主客户端类,提供所有核心功能。
311
+
312
+ #### 方法
313
+
314
+ - `start(kill_existing=False, update_core=False, wait_time=5)` - 启动客户端
315
+ - `stop()` - 关闭客户端
316
+ - `update_core(max_wait_time=300)` - 更新浏览器内核
317
+ - `get_store_list(use_cache=False)` - 获取店铺列表
318
+ - `find_stores_by_name(name, exact_match=False)` - 搜索店铺
319
+ - `open_store(store_id, **options)` - 通过 ID 打开店铺
320
+ - `open_store_by_name(store_name, exact_match=False, **options)` - 通过名称打开店铺
321
+ - `open_stores_by_names(store_names, max_workers=3, exact_match=False, **options)` - 并发打开多个店铺
322
+ - `close_store(store_id)` - 关闭店铺
323
+
324
+ ### BrowserSession
325
+
326
+ 浏览器会话类,表示一个已打开的店铺。
327
+
328
+ #### 属性
329
+
330
+ - `browser` - DrissionPage 的 Chromium 对象
331
+ - `store_id` - 店铺 ID
332
+ - `store_name` - 店铺名称
333
+ - `port` - 调试端口
334
+
335
+ #### 方法
336
+
337
+ - `get_tab(index=-1)` - 获取标签页
338
+ - `check_ip(ip_check_url=None, timeout=60)` - 检测 IP
339
+ - `open_launcher_page(launcher_page=None, wait_time=6)` - 打开启动页面
340
+ - `navigate(url, wait_time=0)` - 导航到 URL
341
+ - `close()` - 关闭会话
342
+
343
+ ### ZiniaoConfig
344
+
345
+ 配置类。
346
+
347
+ #### 类方法
348
+
349
+ - `from_dict(config_dict)` - 从字典创建
350
+ - `from_json_file(file_path)` - 从 JSON 文件加载
351
+ - `from_env(prefix="ZINIAO_")` - 从环境变量加载
352
+
353
+ #### 方法
354
+
355
+ - `to_dict()` - 转换为字典
356
+ - `to_json_file(file_path)` - 保存到 JSON 文件
357
+ - `get_user_info()` - 获取用户登录信息
358
+
359
+ ## 🔍 常见问题
360
+
361
+ ### 1. 如何获取店铺 ID?
362
+
363
+ 登录紫鸟客户端 → 账号管理 → 选择店铺 → 点击"查看账号" → 账号名称后面的 ID 即为店铺 ID。
364
+
365
+ 不过推荐直接使用 `open_store_by_name()` 方法,通过店铺名称打开。
366
+
367
+ ### 2. 支持哪些操作系统?
368
+
369
+ - ✅ Windows
370
+ - ✅ macOS (Darwin)
371
+ - ✅ Linux
372
+
373
+ ### 3. Python 版本要求?
374
+
375
+ 需要 Python 3.8 或更高版本。
376
+
377
+ ### 4. 如何处理多个重名店铺?
378
+
379
+ 使用精确匹配模式:
380
+
381
+ ```python
382
+ session = client.open_store_by_name("店铺名称", exact_match=True)
383
+ ```
384
+
385
+ 或者先搜索,手动选择:
386
+
387
+ ```python
388
+ stores = client.find_stores_by_name("店铺")
389
+ # 选择第一个
390
+ session = client.open_store(stores[0]['browserOauth'])
391
+ ```
392
+
393
+ ### 5. 客户端启动失败怎么办?
394
+
395
+ 1. 确认客户端路径正确
396
+ 2. 确认端口未被占用
397
+ 3. 手动关闭已运行的紫鸟进程
398
+ 4. 检查登录信息是否正确
399
+
400
+ ### 6. 如何清理缓存?
401
+
402
+ ```python
403
+ from yuehua_ziniao_webdriver import delete_cache, get_cache_size, format_bytes
404
+
405
+ # 查看缓存大小
406
+ size = get_cache_size()
407
+ print(f"缓存大小:{format_bytes(size)}")
408
+
409
+ # 删除缓存(仅 Windows)
410
+ if delete_cache():
411
+ print("缓存已清理")
412
+ ```
413
+
414
+ ## 📝 示例代码
415
+
416
+ 完整的示例代码请查看 [`examples/basic_usage.py`](examples/basic_usage.py)。
417
+
418
+ ## 🤝 贡献
419
+
420
+ 欢迎提交 Issue 和 Pull Request!
421
+
422
+ ## 📄 许可证
423
+
424
+ 本项目采用 [MIT 许可证](LICENSE)。
425
+
426
+ ## 📮 联系方式
427
+
428
+ - 作者:Yuehua
429
+ - 邮箱:shengxi_2000@outlook.com
430
+
431
+ ## 🙏 致谢
432
+
433
+ - [DrissionPage](https://github.com/g1879/DrissionPage) - 提供浏览器控制功能
434
+ - [紫鸟浏览器](https://www.ziniao123.com/) - 提供多账号管理能力
435
+
436
+ ---
437
+
438
+ **注意**:本 SDK 仅用于学习和个人项目,请遵守紫鸟浏览器的使用条款。