crawlo 1.0.9__tar.gz → 1.1.1__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.

Potentially problematic release.


This version of crawlo might be problematic. Click here for more details.

Files changed (126) hide show
  1. {crawlo-1.0.9 → crawlo-1.1.1}/LICENSE +22 -22
  2. {crawlo-1.0.9 → crawlo-1.1.1}/MANIFEST.in +16 -16
  3. crawlo-1.1.1/PKG-INFO +220 -0
  4. crawlo-1.1.1/README.md +170 -0
  5. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/__init__.py +33 -24
  6. crawlo-1.1.1/crawlo/__version__.py +1 -0
  7. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/cli.py +40 -40
  8. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/commands/__init__.py +13 -13
  9. crawlo-1.1.1/crawlo/commands/check.py +595 -0
  10. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/commands/genspider.py +125 -110
  11. crawlo-1.1.1/crawlo/commands/list.py +147 -0
  12. crawlo-1.1.1/crawlo/commands/run.py +286 -0
  13. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/commands/startproject.py +111 -101
  14. crawlo-1.1.1/crawlo/commands/stats.py +188 -0
  15. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/core/__init__.py +2 -2
  16. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/core/engine.py +158 -158
  17. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/core/processor.py +40 -40
  18. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/core/scheduler.py +57 -57
  19. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/crawler.py +494 -492
  20. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/downloader/__init__.py +78 -78
  21. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/downloader/aiohttp_downloader.py +199 -199
  22. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/downloader/cffi_downloader.py +242 -277
  23. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/downloader/httpx_downloader.py +246 -246
  24. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/event.py +11 -11
  25. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/exceptions.py +78 -78
  26. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/extension/__init__.py +31 -31
  27. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/extension/log_interval.py +49 -49
  28. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/extension/log_stats.py +44 -44
  29. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/extension/logging_extension.py +34 -34
  30. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/filters/__init__.py +37 -37
  31. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/filters/aioredis_filter.py +150 -150
  32. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/filters/memory_filter.py +202 -202
  33. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/items/__init__.py +23 -23
  34. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/items/base.py +21 -21
  35. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/items/fields.py +53 -53
  36. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/items/items.py +104 -104
  37. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/middleware/__init__.py +21 -21
  38. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/middleware/default_header.py +32 -32
  39. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/middleware/download_delay.py +28 -28
  40. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/middleware/middleware_manager.py +135 -135
  41. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/middleware/proxy.py +245 -245
  42. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/middleware/request_ignore.py +30 -30
  43. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/middleware/response_code.py +18 -18
  44. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/middleware/response_filter.py +26 -26
  45. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/middleware/retry.py +90 -90
  46. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/network/__init__.py +7 -7
  47. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/network/request.py +203 -203
  48. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/network/response.py +166 -166
  49. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/pipelines/__init__.py +13 -13
  50. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/pipelines/console_pipeline.py +39 -39
  51. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/pipelines/mongo_pipeline.py +116 -116
  52. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/pipelines/mysql_batch_pipline.py +272 -272
  53. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/pipelines/mysql_pipeline.py +195 -195
  54. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/pipelines/pipeline_manager.py +56 -56
  55. crawlo-1.1.1/crawlo/project.py +153 -0
  56. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/settings/__init__.py +7 -7
  57. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/settings/default_settings.py +166 -168
  58. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/settings/setting_manager.py +99 -99
  59. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/spider/__init__.py +129 -129
  60. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/stats_collector.py +59 -59
  61. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/subscriber.py +106 -106
  62. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/task_manager.py +27 -27
  63. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/templates/crawlo.cfg.tmpl +10 -10
  64. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/templates/project/__init__.py.tmpl +3 -3
  65. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/templates/project/items.py.tmpl +17 -17
  66. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/templates/project/middlewares.py.tmpl +75 -75
  67. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/templates/project/pipelines.py.tmpl +63 -63
  68. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/templates/project/settings.py.tmpl +54 -54
  69. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/templates/project/spiders/__init__.py.tmpl +5 -5
  70. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/templates/spider/spider.py.tmpl +31 -31
  71. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/utils/__init__.py +7 -7
  72. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/utils/date_tools.py +233 -233
  73. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/utils/db_helper.py +343 -343
  74. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/utils/func_tools.py +82 -82
  75. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/utils/log.py +128 -128
  76. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/utils/pqueue.py +173 -173
  77. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/utils/request.py +267 -267
  78. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/utils/spider_loader.py +62 -62
  79. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/utils/system.py +11 -11
  80. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/utils/tools.py +4 -4
  81. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo/utils/url.py +39 -39
  82. crawlo-1.1.1/crawlo.egg-info/PKG-INFO +220 -0
  83. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo.egg-info/SOURCES.txt +12 -9
  84. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo.egg-info/requires.txt +3 -0
  85. crawlo-1.1.1/examples/__init__.py +7 -0
  86. crawlo-1.1.1/examples/baidu_spider/__init__.py +7 -0
  87. crawlo-1.1.1/examples/baidu_spider/demo.py +94 -0
  88. crawlo-1.1.1/examples/baidu_spider/items.py +46 -0
  89. crawlo-1.1.1/examples/baidu_spider/middleware.py +49 -0
  90. crawlo-1.1.1/examples/baidu_spider/pipeline.py +55 -0
  91. crawlo-1.1.1/examples/baidu_spider/run.py +27 -0
  92. crawlo-1.1.1/examples/baidu_spider/settings.py +121 -0
  93. crawlo-1.1.1/examples/baidu_spider/spiders/__init__.py +7 -0
  94. crawlo-1.1.1/examples/baidu_spider/spiders/bai_du.py +61 -0
  95. crawlo-1.1.1/examples/baidu_spider/spiders/miit.py +159 -0
  96. crawlo-1.1.1/examples/baidu_spider/spiders/sina.py +79 -0
  97. {crawlo-1.0.9 → crawlo-1.1.1}/pyproject.toml +2 -2
  98. {crawlo-1.0.9 → crawlo-1.1.1}/requirements.txt +29 -28
  99. {crawlo-1.0.9 → crawlo-1.1.1}/setup.cfg +71 -68
  100. {crawlo-1.0.9 → crawlo-1.1.1}/tests/__init__.py +7 -7
  101. {crawlo-1.0.9 → crawlo-1.1.1}/tests/test_proxy_health_check.py +32 -32
  102. {crawlo-1.0.9 → crawlo-1.1.1}/tests/test_proxy_middleware_integration.py +136 -136
  103. {crawlo-1.0.9 → crawlo-1.1.1}/tests/test_proxy_providers.py +56 -56
  104. {crawlo-1.0.9 → crawlo-1.1.1}/tests/test_proxy_stats.py +19 -19
  105. {crawlo-1.0.9 → crawlo-1.1.1}/tests/test_proxy_strategies.py +59 -59
  106. crawlo-1.0.9/PKG-INFO +0 -49
  107. crawlo-1.0.9/README.md +0 -2
  108. crawlo-1.0.9/crawlo/__version__.py +0 -1
  109. crawlo-1.0.9/crawlo/commands/check.py +0 -107
  110. crawlo-1.0.9/crawlo/commands/list.py +0 -92
  111. crawlo-1.0.9/crawlo/commands/run.py +0 -181
  112. crawlo-1.0.9/crawlo/commands/stats.py +0 -59
  113. crawlo-1.0.9/crawlo/utils/concurrency_manager.py +0 -125
  114. crawlo-1.0.9/crawlo/utils/project.py +0 -197
  115. crawlo-1.0.9/crawlo.egg-info/PKG-INFO +0 -49
  116. crawlo-1.0.9/examples/__init__.py +0 -0
  117. crawlo-1.0.9/examples/gxb/__init__.py +0 -0
  118. crawlo-1.0.9/examples/gxb/items.py +0 -36
  119. crawlo-1.0.9/examples/gxb/run.py +0 -16
  120. crawlo-1.0.9/examples/gxb/settings.py +0 -72
  121. crawlo-1.0.9/examples/gxb/spider/__init__.py +0 -0
  122. crawlo-1.0.9/examples/gxb/spider/miit_spider.py +0 -180
  123. crawlo-1.0.9/examples/gxb/spider/telecom_device.py +0 -129
  124. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo.egg-info/dependency_links.txt +0 -0
  125. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo.egg-info/entry_points.txt +0 -0
  126. {crawlo-1.0.9 → crawlo-1.1.1}/crawlo.egg-info/top_level.txt +0 -0
@@ -1,23 +1,23 @@
1
- MIT License
2
-
3
- Modifications:
4
-
5
- Copyright (c) 2020 crawl-coder <2251018029@qq.com>
6
-
7
- Permission is hereby granted, free of charge, to any person obtaining a copy
8
- of this software and associated documentation files (the "Software"), to deal
9
- in the Software without restriction, including without limitation the rights
10
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
- copies of the Software, and to permit persons to whom the Software is
12
- furnished to do so, subject to the following conditions:
13
-
14
- The above copyright notice and this permission notice shall be included in all
15
- copies or substantial portions of the Software.
16
-
17
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1
+ MIT License
2
+
3
+ Modifications:
4
+
5
+ Copyright (c) 2020 crawl-coder <2251018029@qq.com>
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
23
  SOFTWARE.
@@ -1,17 +1,17 @@
1
- include README.md
2
- include LICENSE
3
- include requirements.txt # 如果根目录有全局requirements.txt
4
- include VERSION # 如果根目录有全局VERSION文件
5
-
6
- # 包内文件包含
7
- recursive-include crawlo/utils/js *
8
- recursive-include crawlo/templates *
9
-
10
- # 测试文件(如果需要在分发包中包含测试)
11
- recursive-include tests *
12
-
13
- # 排除项
14
- global-exclude __pycache__ *.py[cod] .DS_Store *.so
15
- global-exclude *.bak *.swp *.orig *.rej
16
- prune samples # 排除示例目录
1
+ include README.md
2
+ include LICENSE
3
+ include requirements.txt # 如果根目录有全局requirements.txt
4
+ include VERSION # 如果根目录有全局VERSION文件
5
+
6
+ # 包内文件包含
7
+ recursive-include crawlo/utils/js *
8
+ recursive-include crawlo/templates *
9
+
10
+ # 测试文件(如果需要在分发包中包含测试)
11
+ recursive-include tests *
12
+
13
+ # 排除项
14
+ global-exclude __pycache__ *.py[cod] .DS_Store *.so
15
+ global-exclude *.bak *.swp *.orig *.rej
16
+ prune samples # 排除示例目录
17
17
  prune docs # 排除文档目录
crawlo-1.1.1/PKG-INFO ADDED
@@ -0,0 +1,220 @@
1
+ Metadata-Version: 2.4
2
+ Name: crawlo
3
+ Version: 1.1.1
4
+ Summary: Crawlo 是一款基于异步IO的高性能Python爬虫框架,支持分布式抓取。
5
+ Home-page: https://github.com/crawl-coder/Crawlo.git
6
+ Author: crawl-coder
7
+ Author-email: crawlo@qq.com
8
+ License: MIT
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.6
13
+ Description-Content-Type: text/markdown
14
+ Requires-Dist: aiohttp>=3.12.14
15
+ Requires-Dist: aiomysql>=0.2.0
16
+ Requires-Dist: aioredis>=2.0.1
17
+ Requires-Dist: asyncmy>=0.2.10
18
+ Requires-Dist: cssselect>=1.2.0
19
+ Requires-Dist: dateparser>=1.2.2
20
+ Requires-Dist: httpx[http2]>=0.27.0
21
+ Requires-Dist: curl-cffi>=0.13.0
22
+ Requires-Dist: lxml>=5.2.1
23
+ Requires-Dist: motor>=3.7.0
24
+ Requires-Dist: parsel>=1.9.1
25
+ Requires-Dist: pydantic>=2.11.7
26
+ Requires-Dist: pymongo>=4.11
27
+ Requires-Dist: PyMySQL>=1.1.1
28
+ Requires-Dist: python-dateutil>=2.9.0.post0
29
+ Requires-Dist: redis>=6.2.0
30
+ Requires-Dist: requests>=2.32.4
31
+ Requires-Dist: six>=1.17.0
32
+ Requires-Dist: ujson>=5.9.0
33
+ Requires-Dist: urllib3>=2.5.0
34
+ Requires-Dist: w3lib>=2.1.2
35
+ Requires-Dist: rich>=14.1.0
36
+ Requires-Dist: astor>=0.8.1
37
+ Requires-Dist: watchdog>=6.0.0
38
+ Provides-Extra: render
39
+ Requires-Dist: webdriver-manager>=4.0.0; extra == "render"
40
+ Requires-Dist: playwright; extra == "render"
41
+ Requires-Dist: selenium>=3.141.0; extra == "render"
42
+ Provides-Extra: all
43
+ Requires-Dist: bitarray>=1.5.3; extra == "all"
44
+ Requires-Dist: PyExecJS>=1.5.1; extra == "all"
45
+ Requires-Dist: pymongo>=3.10.1; extra == "all"
46
+ Requires-Dist: redis-py-cluster>=2.1.0; extra == "all"
47
+ Requires-Dist: webdriver-manager>=4.0.0; extra == "all"
48
+ Requires-Dist: playwright; extra == "all"
49
+ Requires-Dist: selenium>=3.141.0; extra == "all"
50
+
51
+ # 🕷️ Crawlo - 轻量级异步爬虫框架
52
+
53
+ > 一个简洁、易用、可扩展的 Python 异步爬虫框架,灵感源自 Scrapy,但更轻量、更易上手。
54
+
55
+ 🚀 支持命令行操作、爬虫生成、合规检查、运行监控与统计分析,适合快速开发中小型爬虫项目。
56
+
57
+ ---
58
+
59
+ ## 📦 特性
60
+
61
+ - ✅ **命令行驱动**:`crawlo startproject`, `crawlo genspider` 等
62
+ - ✅ **自动发现爬虫**:无需手动注册,自动加载 `spiders/` 模块
63
+ - ✅ **异步核心**:基于 `asyncio` 实现高并发抓取
64
+ - ✅ **灵活配置**:通过 `crawlo.cfg` 和 `settings.py` 管理项目
65
+ - ✅ **爬虫检查**:`crawlo check` 验证爬虫定义是否合规
66
+ - ✅ **运行统计**:`crawlo stats` 查看历史运行指标(持久化存储)
67
+ - ✅ **批量运行**:支持 `crawlo run all` 启动所有爬虫
68
+ - ✅ **日志与调试**:结构化日志输出,便于排查问题
69
+
70
+ ---
71
+
72
+ ## 🚀 快速开始
73
+
74
+ ### 1. 安装 Crawlo
75
+
76
+ ```bash
77
+ pip install crawlo
78
+ ```
79
+
80
+ > ⚠️ 当前为开发阶段,建议使用源码安装:
81
+ >
82
+ > ```bash
83
+ > git clone https://github.com/yourname/crawlo.git
84
+ > pip install -e crawlo
85
+ > ```
86
+
87
+ ### 2. 创建项目
88
+
89
+ ```bash
90
+ crawlo startproject myproject
91
+ cd myproject
92
+ ```
93
+
94
+ 生成项目结构:
95
+
96
+ ```
97
+ myproject/
98
+ ├── crawlo.cfg
99
+ ├── myproject/
100
+ │ ├── __init__.py
101
+ │ ├── settings.py
102
+ │ └── spiders/
103
+ │ ├── __init__.py
104
+ │ └── (你的爬虫将在这里)
105
+ ```
106
+
107
+ ### 3. 生成爬虫
108
+
109
+ ```bash
110
+ crawlo genspider example example.com
111
+ ```
112
+
113
+ 生成 `spiders/example.py`:
114
+
115
+ ```python
116
+ class ExampleSpider(Spider):
117
+ name = "example"
118
+ start_urls = ["https://example.com"]
119
+
120
+ def parse(self, response):
121
+ # 解析逻辑
122
+ pass
123
+ ```
124
+
125
+ ### 4. 检查爬虫合规性
126
+
127
+ ```bash
128
+ crawlo check
129
+ ```
130
+
131
+ 输出示例:
132
+
133
+ ```
134
+ 🔍 Checking 1 spider(s)...
135
+ ✅ example ExampleSpider (OK)
136
+ 🎉 All spiders are compliant!
137
+ ```
138
+
139
+ ### 5. 运行爬虫
140
+
141
+ ```bash
142
+ # 运行单个爬虫
143
+ crawlo run example
144
+
145
+ # 运行所有爬虫
146
+ crawlo run all
147
+ ```
148
+
149
+ ### 6. 查看运行统计
150
+
151
+ ```bash
152
+ crawlo stats
153
+ ```
154
+
155
+ 查看最近一次运行的请求、响应、项目数等指标:
156
+
157
+ ```
158
+ 📊 Recent Spider Statistics (last run):
159
+ 🕷️ example
160
+ downloader/request_count 1
161
+ item_scraped_count 1
162
+ log_count/INFO 7
163
+ ```
164
+
165
+ ---
166
+
167
+ ## 🛠️ 命令列表
168
+
169
+ | 命令 | 说明 |
170
+ |------|------|
171
+ | `crawlo startproject <name>` | 创建新项目 |
172
+ | `crawlo genspider <name> <domain>` | 生成爬虫模板 |
173
+ | `crawlo list` | 列出所有已注册的爬虫 |
174
+ | `crawlo check` | 检查爬虫定义是否合规 |
175
+ | `crawlo run <spider_name>` | 运行指定爬虫 |
176
+ | `crawlo run all` | 运行所有爬虫 |
177
+ | `crawlo stats` | 查看最近运行的统计信息 |
178
+ | `crawlo stats <spider_name>` | 查看指定爬虫的统计 |
179
+
180
+ ---
181
+
182
+ ## 📁 项目结构说明
183
+
184
+ ```ini
185
+ # crawlo.cfg
186
+ [settings]
187
+ default = myproject.settings
188
+ ```
189
+
190
+ ```python
191
+ # settings.py
192
+ BOT_NAME = "myproject"
193
+ LOG_LEVEL = "DEBUG"
194
+ CONCURRENT_REQUESTS = 3
195
+ DOWNLOAD_DELAY = 1.0
196
+ # 其他配置...
197
+ ```
198
+
199
+ ---
200
+
201
+ ## 📊 统计持久化
202
+
203
+ 每次爬虫运行结束后,统计信息会自动保存到:
204
+
205
+ ```
206
+ logs/stats/<spider_name>_YYYYMMDD_HHMMSS.json
207
+ ```
208
+
209
+ 可通过 `crawlo stats` 命令读取,支持跨进程查看。
210
+
211
+ ---
212
+
213
+ ## 🧪 开发者提示
214
+
215
+ - 确保 `spiders/__init__.py` 中导入了你的爬虫类,否则无法被发现
216
+ - 使用 `get_project_root()` 自动定位项目根目录(通过查找 `crawlo.cfg`)
217
+ - 所有命令行工具均支持直接运行:`python -m crawlo.commands.list`
218
+
219
+ ---
220
+
crawlo-1.1.1/README.md ADDED
@@ -0,0 +1,170 @@
1
+ # 🕷️ Crawlo - 轻量级异步爬虫框架
2
+
3
+ > 一个简洁、易用、可扩展的 Python 异步爬虫框架,灵感源自 Scrapy,但更轻量、更易上手。
4
+
5
+ 🚀 支持命令行操作、爬虫生成、合规检查、运行监控与统计分析,适合快速开发中小型爬虫项目。
6
+
7
+ ---
8
+
9
+ ## 📦 特性
10
+
11
+ - ✅ **命令行驱动**:`crawlo startproject`, `crawlo genspider` 等
12
+ - ✅ **自动发现爬虫**:无需手动注册,自动加载 `spiders/` 模块
13
+ - ✅ **异步核心**:基于 `asyncio` 实现高并发抓取
14
+ - ✅ **灵活配置**:通过 `crawlo.cfg` 和 `settings.py` 管理项目
15
+ - ✅ **爬虫检查**:`crawlo check` 验证爬虫定义是否合规
16
+ - ✅ **运行统计**:`crawlo stats` 查看历史运行指标(持久化存储)
17
+ - ✅ **批量运行**:支持 `crawlo run all` 启动所有爬虫
18
+ - ✅ **日志与调试**:结构化日志输出,便于排查问题
19
+
20
+ ---
21
+
22
+ ## 🚀 快速开始
23
+
24
+ ### 1. 安装 Crawlo
25
+
26
+ ```bash
27
+ pip install crawlo
28
+ ```
29
+
30
+ > ⚠️ 当前为开发阶段,建议使用源码安装:
31
+ >
32
+ > ```bash
33
+ > git clone https://github.com/yourname/crawlo.git
34
+ > pip install -e crawlo
35
+ > ```
36
+
37
+ ### 2. 创建项目
38
+
39
+ ```bash
40
+ crawlo startproject myproject
41
+ cd myproject
42
+ ```
43
+
44
+ 生成项目结构:
45
+
46
+ ```
47
+ myproject/
48
+ ├── crawlo.cfg
49
+ ├── myproject/
50
+ │ ├── __init__.py
51
+ │ ├── settings.py
52
+ │ └── spiders/
53
+ │ ├── __init__.py
54
+ │ └── (你的爬虫将在这里)
55
+ ```
56
+
57
+ ### 3. 生成爬虫
58
+
59
+ ```bash
60
+ crawlo genspider example example.com
61
+ ```
62
+
63
+ 生成 `spiders/example.py`:
64
+
65
+ ```python
66
+ class ExampleSpider(Spider):
67
+ name = "example"
68
+ start_urls = ["https://example.com"]
69
+
70
+ def parse(self, response):
71
+ # 解析逻辑
72
+ pass
73
+ ```
74
+
75
+ ### 4. 检查爬虫合规性
76
+
77
+ ```bash
78
+ crawlo check
79
+ ```
80
+
81
+ 输出示例:
82
+
83
+ ```
84
+ 🔍 Checking 1 spider(s)...
85
+ ✅ example ExampleSpider (OK)
86
+ 🎉 All spiders are compliant!
87
+ ```
88
+
89
+ ### 5. 运行爬虫
90
+
91
+ ```bash
92
+ # 运行单个爬虫
93
+ crawlo run example
94
+
95
+ # 运行所有爬虫
96
+ crawlo run all
97
+ ```
98
+
99
+ ### 6. 查看运行统计
100
+
101
+ ```bash
102
+ crawlo stats
103
+ ```
104
+
105
+ 查看最近一次运行的请求、响应、项目数等指标:
106
+
107
+ ```
108
+ 📊 Recent Spider Statistics (last run):
109
+ 🕷️ example
110
+ downloader/request_count 1
111
+ item_scraped_count 1
112
+ log_count/INFO 7
113
+ ```
114
+
115
+ ---
116
+
117
+ ## 🛠️ 命令列表
118
+
119
+ | 命令 | 说明 |
120
+ |------|------|
121
+ | `crawlo startproject <name>` | 创建新项目 |
122
+ | `crawlo genspider <name> <domain>` | 生成爬虫模板 |
123
+ | `crawlo list` | 列出所有已注册的爬虫 |
124
+ | `crawlo check` | 检查爬虫定义是否合规 |
125
+ | `crawlo run <spider_name>` | 运行指定爬虫 |
126
+ | `crawlo run all` | 运行所有爬虫 |
127
+ | `crawlo stats` | 查看最近运行的统计信息 |
128
+ | `crawlo stats <spider_name>` | 查看指定爬虫的统计 |
129
+
130
+ ---
131
+
132
+ ## 📁 项目结构说明
133
+
134
+ ```ini
135
+ # crawlo.cfg
136
+ [settings]
137
+ default = myproject.settings
138
+ ```
139
+
140
+ ```python
141
+ # settings.py
142
+ BOT_NAME = "myproject"
143
+ LOG_LEVEL = "DEBUG"
144
+ CONCURRENT_REQUESTS = 3
145
+ DOWNLOAD_DELAY = 1.0
146
+ # 其他配置...
147
+ ```
148
+
149
+ ---
150
+
151
+ ## 📊 统计持久化
152
+
153
+ 每次爬虫运行结束后,统计信息会自动保存到:
154
+
155
+ ```
156
+ logs/stats/<spider_name>_YYYYMMDD_HHMMSS.json
157
+ ```
158
+
159
+ 可通过 `crawlo stats` 命令读取,支持跨进程查看。
160
+
161
+ ---
162
+
163
+ ## 🧪 开发者提示
164
+
165
+ - 确保 `spiders/__init__.py` 中导入了你的爬虫类,否则无法被发现
166
+ - 使用 `get_project_root()` 自动定位项目根目录(通过查找 `crawlo.cfg`)
167
+ - 所有命令行工具均支持直接运行:`python -m crawlo.commands.list`
168
+
169
+ ---
170
+
@@ -1,25 +1,34 @@
1
- #!/usr/bin/python
2
- # -*- coding: UTF-8 -*-
3
- """
4
- Crawlo - 一个异步爬虫框架
5
- """
6
- from crawlo.spider import Spider
7
- from crawlo.items.items import Item
8
- from crawlo.network.request import Request
9
- from crawlo.network.response import Response
10
- from crawlo.downloader import DownloaderBase
11
- from crawlo.middleware import BaseMiddleware
12
-
13
- # 版本号
14
- from crawlo.__version__ import __version__
15
-
16
- # 可选:定义对外暴露的接口
17
- __all__ = [
18
- 'Spider',
19
- 'Item',
20
- 'Request',
21
- 'Response',
22
- 'DownloaderBase',
23
- 'BaseMiddleware',
24
- '__version__',
1
+ #!/usr/bin/python
2
+ # -*- coding: UTF-8 -*-
3
+ """
4
+ Crawlo - 一个异步爬虫框架
5
+ """
6
+ from crawlo.spider import Spider
7
+ from crawlo.items.items import Item
8
+ from crawlo.network.request import Request
9
+ from crawlo.network.response import Response
10
+ from crawlo.downloader import DownloaderBase
11
+ from crawlo.middleware import BaseMiddleware
12
+
13
+
14
+ # 版本号:优先从元数据读取
15
+ try:
16
+ from importlib.metadata import version
17
+ __version__ = version("crawlo")
18
+ except Exception:
19
+ # 开发模式下可能未安装,回退到 __version__.py 或 dev
20
+ try:
21
+ from crawlo.__version__ import __version__
22
+ except ImportError:
23
+ __version__ = "dev"
24
+
25
+ # 定义对外 API
26
+ __all__ = [
27
+ 'Spider',
28
+ 'Item',
29
+ 'Request',
30
+ 'Response',
31
+ 'DownloaderBase',
32
+ 'BaseMiddleware',
33
+ '__version__',
25
34
  ]
@@ -0,0 +1 @@
1
+ __version__ = "1.1.1"
@@ -1,41 +1,41 @@
1
- # crawlo/cli.py
2
- # !/usr/bin/python
3
- # -*- coding: UTF-8 -*-
4
- import sys
5
- import argparse
6
- from crawlo.commands import get_commands
7
-
8
-
9
- def main():
10
- # 获取所有可用命令
11
- commands = get_commands()
12
-
13
- parser = argparse.ArgumentParser(
14
- description="Crawlo: A lightweight web crawler framework.",
15
- usage="crawlo <command> [options]"
16
- )
17
- parser.add_argument('command', help='Available commands: ' + ', '.join(commands.keys()))
18
- # 注意:这里不添加具体参数,由子命令解析
19
-
20
- # 只解析命令
21
- args, unknown = parser.parse_known_args()
22
-
23
- if args.command not in commands:
24
- print(f"Unknown command: {args.command}")
25
- print(f"Available commands: {', '.join(commands.keys())}")
26
- sys.exit(1)
27
-
28
- # 动态导入并执行命令
29
- try:
30
- module = __import__(commands[args.command], fromlist=['main'])
31
- sys.exit(module.main(unknown))
32
- except ImportError as e:
33
- print(f"Failed to load command '{args.command}': {e}")
34
- sys.exit(1)
35
- except Exception as e:
36
- print(f"Command '{args.command}' failed: {e}")
37
- sys.exit(1)
38
-
39
-
40
- if __name__ == '__main__':
1
+ # crawlo/cli.py
2
+ # !/usr/bin/python
3
+ # -*- coding: UTF-8 -*-
4
+ import sys
5
+ import argparse
6
+ from crawlo.commands import get_commands
7
+
8
+
9
+ def main():
10
+ # 获取所有可用命令
11
+ commands = get_commands()
12
+
13
+ parser = argparse.ArgumentParser(
14
+ description="Crawlo: A lightweight web crawler framework.",
15
+ usage="crawlo <command> [options]"
16
+ )
17
+ parser.add_argument('command', help='Available commands: ' + ', '.join(commands.keys()))
18
+ # 注意:这里不添加具体参数,由子命令解析
19
+
20
+ # 只解析命令
21
+ args, unknown = parser.parse_known_args()
22
+
23
+ if args.command not in commands:
24
+ print(f"Unknown command: {args.command}")
25
+ print(f"Available commands: {', '.join(commands.keys())}")
26
+ sys.exit(1)
27
+
28
+ # 动态导入并执行命令
29
+ try:
30
+ module = __import__(commands[args.command], fromlist=['main'])
31
+ sys.exit(module.main(unknown))
32
+ except ImportError as e:
33
+ print(f"Failed to load command '{args.command}': {e}")
34
+ sys.exit(1)
35
+ except Exception as e:
36
+ print(f"Command '{args.command}' failed: {e}")
37
+ sys.exit(1)
38
+
39
+
40
+ if __name__ == '__main__':
41
41
  main()
@@ -1,14 +1,14 @@
1
- #!/usr/bin/python
2
- # -*- coding:UTF-8 -*-
3
-
4
- _commands = {
5
- 'startproject': 'crawlo.commands.startproject',
6
- 'genspider': 'crawlo.commands.genspider',
7
- 'run': 'crawlo.commands.run',
8
- 'check': 'crawlo.commands.check',
9
- 'list': 'crawlo.commands.list',
10
- 'stats': 'crawlo.commands.stats'
11
- }
12
-
13
- def get_commands():
1
+ #!/usr/bin/python
2
+ # -*- coding:UTF-8 -*-
3
+
4
+ _commands = {
5
+ 'startproject': 'crawlo.commands.startproject',
6
+ 'genspider': 'crawlo.commands.genspider',
7
+ 'run': 'crawlo.commands.run',
8
+ 'check': 'crawlo.commands.check',
9
+ 'list': 'crawlo.commands.list',
10
+ 'stats': 'crawlo.commands.stats'
11
+ }
12
+
13
+ def get_commands():
14
14
  return _commands