crawlo 1.1.0__py3-none-any.whl → 1.1.1__py3-none-any.whl
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.
- crawlo/__init__.py +33 -24
- crawlo/__version__.py +1 -1
- crawlo/cli.py +40 -40
- crawlo/commands/__init__.py +13 -13
- crawlo/commands/check.py +594 -155
- crawlo/commands/genspider.py +125 -110
- crawlo/commands/list.py +147 -119
- crawlo/commands/run.py +285 -170
- crawlo/commands/startproject.py +111 -101
- crawlo/commands/stats.py +188 -167
- crawlo/core/__init__.py +2 -2
- crawlo/core/engine.py +158 -158
- crawlo/core/processor.py +40 -40
- crawlo/core/scheduler.py +57 -57
- crawlo/crawler.py +494 -492
- crawlo/downloader/__init__.py +78 -78
- crawlo/downloader/aiohttp_downloader.py +199 -199
- crawlo/downloader/cffi_downloader.py +242 -277
- crawlo/downloader/httpx_downloader.py +246 -246
- crawlo/event.py +11 -11
- crawlo/exceptions.py +78 -78
- crawlo/extension/__init__.py +31 -31
- crawlo/extension/log_interval.py +49 -49
- crawlo/extension/log_stats.py +44 -44
- crawlo/extension/logging_extension.py +34 -34
- crawlo/filters/__init__.py +37 -37
- crawlo/filters/aioredis_filter.py +150 -150
- crawlo/filters/memory_filter.py +202 -202
- crawlo/items/__init__.py +23 -23
- crawlo/items/base.py +21 -21
- crawlo/items/fields.py +53 -53
- crawlo/items/items.py +104 -104
- crawlo/middleware/__init__.py +21 -21
- crawlo/middleware/default_header.py +32 -32
- crawlo/middleware/download_delay.py +28 -28
- crawlo/middleware/middleware_manager.py +135 -135
- crawlo/middleware/proxy.py +245 -245
- crawlo/middleware/request_ignore.py +30 -30
- crawlo/middleware/response_code.py +18 -18
- crawlo/middleware/response_filter.py +26 -26
- crawlo/middleware/retry.py +90 -90
- crawlo/network/__init__.py +7 -7
- crawlo/network/request.py +203 -203
- crawlo/network/response.py +166 -166
- crawlo/pipelines/__init__.py +13 -13
- crawlo/pipelines/console_pipeline.py +39 -39
- crawlo/pipelines/mongo_pipeline.py +116 -116
- crawlo/pipelines/mysql_batch_pipline.py +272 -272
- crawlo/pipelines/mysql_pipeline.py +195 -195
- crawlo/pipelines/pipeline_manager.py +56 -56
- crawlo/project.py +153 -0
- crawlo/settings/__init__.py +7 -7
- crawlo/settings/default_settings.py +166 -168
- crawlo/settings/setting_manager.py +99 -99
- crawlo/spider/__init__.py +129 -129
- crawlo/stats_collector.py +59 -59
- crawlo/subscriber.py +106 -106
- crawlo/task_manager.py +27 -27
- crawlo/templates/crawlo.cfg.tmpl +10 -10
- crawlo/templates/project/__init__.py.tmpl +3 -3
- crawlo/templates/project/items.py.tmpl +17 -17
- crawlo/templates/project/middlewares.py.tmpl +75 -75
- crawlo/templates/project/pipelines.py.tmpl +63 -63
- crawlo/templates/project/settings.py.tmpl +54 -54
- crawlo/templates/project/spiders/__init__.py.tmpl +5 -5
- crawlo/templates/spider/spider.py.tmpl +31 -31
- crawlo/utils/__init__.py +7 -7
- crawlo/utils/date_tools.py +233 -233
- crawlo/utils/db_helper.py +343 -343
- crawlo/utils/func_tools.py +82 -82
- crawlo/utils/log.py +128 -128
- crawlo/utils/pqueue.py +173 -173
- crawlo/utils/request.py +267 -267
- crawlo/utils/spider_loader.py +62 -62
- crawlo/utils/system.py +11 -11
- crawlo/utils/tools.py +4 -4
- crawlo/utils/url.py +39 -39
- crawlo-1.1.1.dist-info/METADATA +220 -0
- crawlo-1.1.1.dist-info/RECORD +100 -0
- examples/__init__.py +7 -0
- examples/baidu_spider/__init__.py +7 -0
- examples/baidu_spider/demo.py +94 -0
- examples/baidu_spider/items.py +46 -0
- examples/baidu_spider/middleware.py +49 -0
- examples/baidu_spider/pipeline.py +55 -0
- examples/baidu_spider/run.py +27 -0
- examples/baidu_spider/settings.py +121 -0
- examples/baidu_spider/spiders/__init__.py +7 -0
- examples/baidu_spider/spiders/bai_du.py +61 -0
- examples/baidu_spider/spiders/miit.py +159 -0
- examples/baidu_spider/spiders/sina.py +79 -0
- tests/__init__.py +7 -7
- tests/test_proxy_health_check.py +32 -32
- tests/test_proxy_middleware_integration.py +136 -136
- tests/test_proxy_providers.py +56 -56
- tests/test_proxy_stats.py +19 -19
- tests/test_proxy_strategies.py +59 -59
- crawlo/utils/concurrency_manager.py +0 -125
- crawlo/utils/project.py +0 -197
- crawlo-1.1.0.dist-info/METADATA +0 -49
- crawlo-1.1.0.dist-info/RECORD +0 -97
- examples/gxb/__init__.py +0 -0
- examples/gxb/items.py +0 -36
- examples/gxb/run.py +0 -16
- examples/gxb/settings.py +0 -72
- examples/gxb/spider/__init__.py +0 -2
- examples/gxb/spider/miit_spider.py +0 -180
- examples/gxb/spider/telecom_device.py +0 -129
- {crawlo-1.1.0.dist-info → crawlo-1.1.1.dist-info}/WHEEL +0 -0
- {crawlo-1.1.0.dist-info → crawlo-1.1.1.dist-info}/entry_points.txt +0 -0
- {crawlo-1.1.0.dist-info → crawlo-1.1.1.dist-info}/top_level.txt +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# -*- coding: UTF-8 -*-
|
|
2
|
-
"""
|
|
3
|
-
{{project_name}} 项目包
|
|
1
|
+
# -*- coding: UTF-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
{{project_name}} 项目包
|
|
4
4
|
"""
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
# -*- coding: UTF-8 -*-
|
|
2
|
-
"""
|
|
3
|
-
{{project_name}}.items
|
|
4
|
-
======================
|
|
5
|
-
定义你抓取的数据结构。
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
from crawlo.items import Item, Field
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class ExampleItem(Item):
|
|
12
|
-
"""
|
|
13
|
-
一个示例数据项。
|
|
14
|
-
"""
|
|
15
|
-
# name = Field()
|
|
16
|
-
# price = Field()
|
|
17
|
-
# description = Field()
|
|
1
|
+
# -*- coding: UTF-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
{{project_name}}.items
|
|
4
|
+
======================
|
|
5
|
+
定义你抓取的数据结构。
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from crawlo.items import Item, Field
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class ExampleItem(Item):
|
|
12
|
+
"""
|
|
13
|
+
一个示例数据项。
|
|
14
|
+
"""
|
|
15
|
+
# name = Field()
|
|
16
|
+
# price = Field()
|
|
17
|
+
# description = Field()
|
|
18
18
|
pass
|
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
# -*- coding: UTF-8 -*-
|
|
2
|
-
"""
|
|
3
|
-
{{project_name}}.middlewares
|
|
4
|
-
============================
|
|
5
|
-
自定义中间件,用于在请求/响应/异常处理过程中插入自定义逻辑。
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
# 示例:下载器中间件
|
|
9
|
-
class CustomDownloaderMiddleware:
|
|
10
|
-
"""
|
|
11
|
-
下载器中间件示例。
|
|
12
|
-
"""
|
|
13
|
-
|
|
14
|
-
def process_request(self, request, spider):
|
|
15
|
-
"""
|
|
16
|
-
在请求被下载器执行前调用。
|
|
17
|
-
"""
|
|
18
|
-
# request.headers['User-Agent'] = 'Custom UA'
|
|
19
|
-
# return None # 继续处理
|
|
20
|
-
# return request # 修改并返回
|
|
21
|
-
# return Response(...) # 返回一个响应,停止下载
|
|
22
|
-
pass
|
|
23
|
-
|
|
24
|
-
def process_response(self, request, response, spider):
|
|
25
|
-
"""
|
|
26
|
-
在响应被 Spider 处理前调用。
|
|
27
|
-
"""
|
|
28
|
-
# return response # 继续处理
|
|
29
|
-
# return request # 重试请求
|
|
30
|
-
pass
|
|
31
|
-
|
|
32
|
-
def process_exception(self, request, exception, spider):
|
|
33
|
-
"""
|
|
34
|
-
在下载或处理过程中发生异常时调用。
|
|
35
|
-
"""
|
|
36
|
-
# return None # 继续抛出异常
|
|
37
|
-
# return request # 重试
|
|
38
|
-
# return Response(...) # 返回一个响应
|
|
39
|
-
pass
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
# 示例:Spider 中间件
|
|
43
|
-
class CustomSpiderMiddleware:
|
|
44
|
-
"""
|
|
45
|
-
Spider 中间件示例。
|
|
46
|
-
"""
|
|
47
|
-
|
|
48
|
-
def process_spider_input(self, response, spider):
|
|
49
|
-
"""
|
|
50
|
-
在 Spider 的 parse 方法被调用前调用。
|
|
51
|
-
"""
|
|
52
|
-
# 可以用来验证响应
|
|
53
|
-
pass
|
|
54
|
-
|
|
55
|
-
def process_spider_output(self, response, result, spider):
|
|
56
|
-
"""
|
|
57
|
-
在 Spider 的 parse 方法返回结果后调用。
|
|
58
|
-
"""
|
|
59
|
-
# 可以用来过滤或修改结果
|
|
60
|
-
# for item in result:
|
|
61
|
-
# yield item
|
|
62
|
-
pass
|
|
63
|
-
|
|
64
|
-
def process_spider_exception(self, response, exception, spider):
|
|
65
|
-
"""
|
|
66
|
-
在 Spider 的 parse 方法抛出异常时调用。
|
|
67
|
-
"""
|
|
68
|
-
pass
|
|
69
|
-
|
|
70
|
-
def process_start_requests(self, start_requests, spider):
|
|
71
|
-
"""
|
|
72
|
-
在 Spider 的 start_requests 生成器被消费时调用。
|
|
73
|
-
"""
|
|
74
|
-
# for request in start_requests:
|
|
75
|
-
# yield request
|
|
1
|
+
# -*- coding: UTF-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
{{project_name}}.middlewares
|
|
4
|
+
============================
|
|
5
|
+
自定义中间件,用于在请求/响应/异常处理过程中插入自定义逻辑。
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
# 示例:下载器中间件
|
|
9
|
+
class CustomDownloaderMiddleware:
|
|
10
|
+
"""
|
|
11
|
+
下载器中间件示例。
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
def process_request(self, request, spider):
|
|
15
|
+
"""
|
|
16
|
+
在请求被下载器执行前调用。
|
|
17
|
+
"""
|
|
18
|
+
# request.headers['User-Agent'] = 'Custom UA'
|
|
19
|
+
# return None # 继续处理
|
|
20
|
+
# return request # 修改并返回
|
|
21
|
+
# return Response(...) # 返回一个响应,停止下载
|
|
22
|
+
pass
|
|
23
|
+
|
|
24
|
+
def process_response(self, request, response, spider):
|
|
25
|
+
"""
|
|
26
|
+
在响应被 Spider 处理前调用。
|
|
27
|
+
"""
|
|
28
|
+
# return response # 继续处理
|
|
29
|
+
# return request # 重试请求
|
|
30
|
+
pass
|
|
31
|
+
|
|
32
|
+
def process_exception(self, request, exception, spider):
|
|
33
|
+
"""
|
|
34
|
+
在下载或处理过程中发生异常时调用。
|
|
35
|
+
"""
|
|
36
|
+
# return None # 继续抛出异常
|
|
37
|
+
# return request # 重试
|
|
38
|
+
# return Response(...) # 返回一个响应
|
|
39
|
+
pass
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
# 示例:Spider 中间件
|
|
43
|
+
class CustomSpiderMiddleware:
|
|
44
|
+
"""
|
|
45
|
+
Spider 中间件示例。
|
|
46
|
+
"""
|
|
47
|
+
|
|
48
|
+
def process_spider_input(self, response, spider):
|
|
49
|
+
"""
|
|
50
|
+
在 Spider 的 parse 方法被调用前调用。
|
|
51
|
+
"""
|
|
52
|
+
# 可以用来验证响应
|
|
53
|
+
pass
|
|
54
|
+
|
|
55
|
+
def process_spider_output(self, response, result, spider):
|
|
56
|
+
"""
|
|
57
|
+
在 Spider 的 parse 方法返回结果后调用。
|
|
58
|
+
"""
|
|
59
|
+
# 可以用来过滤或修改结果
|
|
60
|
+
# for item in result:
|
|
61
|
+
# yield item
|
|
62
|
+
pass
|
|
63
|
+
|
|
64
|
+
def process_spider_exception(self, response, exception, spider):
|
|
65
|
+
"""
|
|
66
|
+
在 Spider 的 parse 方法抛出异常时调用。
|
|
67
|
+
"""
|
|
68
|
+
pass
|
|
69
|
+
|
|
70
|
+
def process_start_requests(self, start_requests, spider):
|
|
71
|
+
"""
|
|
72
|
+
在 Spider 的 start_requests 生成器被消费时调用。
|
|
73
|
+
"""
|
|
74
|
+
# for request in start_requests:
|
|
75
|
+
# yield request
|
|
76
76
|
pass
|
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
# -*- coding: UTF-8 -*-
|
|
2
|
-
"""
|
|
3
|
-
{{project_name}}.pipelines
|
|
4
|
-
==========================
|
|
5
|
-
数据管道,用于处理 Spider 返回的 Item。
|
|
6
|
-
例如:清理、验证、去重、保存到数据库等。
|
|
7
|
-
"""
|
|
8
|
-
|
|
9
|
-
class PrintItemPipeline:
|
|
10
|
-
"""
|
|
11
|
-
一个简单的管道,用于打印 Item。
|
|
12
|
-
"""
|
|
13
|
-
|
|
14
|
-
def process_item(self, item, spider):
|
|
15
|
-
print(f"Pipeline received item: {dict(item)}")
|
|
16
|
-
return item
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
class DuplicatesPipeline:
|
|
20
|
-
"""
|
|
21
|
-
一个去重管道示例。
|
|
22
|
-
"""
|
|
23
|
-
def __init__(self):
|
|
24
|
-
self.seen = set()
|
|
25
|
-
|
|
26
|
-
def process_item(self, item, spider):
|
|
27
|
-
identifier = item.get('id') or item.get('url')
|
|
28
|
-
if identifier in self.seen:
|
|
29
|
-
spider.logger.debug(f"Duplicate item found: {identifier}")
|
|
30
|
-
raise DropItem(f"Duplicate item: {identifier}")
|
|
31
|
-
self.seen.add(identifier)
|
|
32
|
-
return item
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
# class MySQLPipeline:
|
|
36
|
-
# """
|
|
37
|
-
# 将 Item 保存到 MySQL 的管道示例。
|
|
38
|
-
# """
|
|
39
|
-
# def __init__(self, mysql_uri, mysql_user, mysql_password, mysql_db):
|
|
40
|
-
# self.mysql_uri = mysql_uri
|
|
41
|
-
# self.mysql_user = mysql_user
|
|
42
|
-
# self.mysql_password = mysql_password
|
|
43
|
-
# self.mysql_db = mysql_db
|
|
44
|
-
# self.connection = None
|
|
45
|
-
#
|
|
46
|
-
# @classmethod
|
|
47
|
-
# def from_settings(cls, settings):
|
|
48
|
-
# return cls(
|
|
49
|
-
# mysql_uri=settings.get('MYSQL_HOST'),
|
|
50
|
-
# mysql_user=settings.get('MYSQL_USER'),
|
|
51
|
-
# mysql_password=settings.get('MYSQL_PASSWORD'),
|
|
52
|
-
# mysql_db=settings.get('MYSQL_DB')
|
|
53
|
-
# )
|
|
54
|
-
#
|
|
55
|
-
# def open_spider(self, spider):
|
|
56
|
-
# self.connection = pymysql.connect(...)
|
|
57
|
-
#
|
|
58
|
-
# def close_spider(self, spider):
|
|
59
|
-
# if self.connection:
|
|
60
|
-
# self.connection.close()
|
|
61
|
-
#
|
|
62
|
-
# def process_item(self, item, spider):
|
|
63
|
-
# # 执行 SQL 插入
|
|
1
|
+
# -*- coding: UTF-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
{{project_name}}.pipelines
|
|
4
|
+
==========================
|
|
5
|
+
数据管道,用于处理 Spider 返回的 Item。
|
|
6
|
+
例如:清理、验证、去重、保存到数据库等。
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
class PrintItemPipeline:
|
|
10
|
+
"""
|
|
11
|
+
一个简单的管道,用于打印 Item。
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
def process_item(self, item, spider):
|
|
15
|
+
print(f"Pipeline received item: {dict(item)}")
|
|
16
|
+
return item
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class DuplicatesPipeline:
|
|
20
|
+
"""
|
|
21
|
+
一个去重管道示例。
|
|
22
|
+
"""
|
|
23
|
+
def __init__(self):
|
|
24
|
+
self.seen = set()
|
|
25
|
+
|
|
26
|
+
def process_item(self, item, spider):
|
|
27
|
+
identifier = item.get('id') or item.get('url')
|
|
28
|
+
if identifier in self.seen:
|
|
29
|
+
spider.logger.debug(f"Duplicate item found: {identifier}")
|
|
30
|
+
raise DropItem(f"Duplicate item: {identifier}")
|
|
31
|
+
self.seen.add(identifier)
|
|
32
|
+
return item
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
# class MySQLPipeline:
|
|
36
|
+
# """
|
|
37
|
+
# 将 Item 保存到 MySQL 的管道示例。
|
|
38
|
+
# """
|
|
39
|
+
# def __init__(self, mysql_uri, mysql_user, mysql_password, mysql_db):
|
|
40
|
+
# self.mysql_uri = mysql_uri
|
|
41
|
+
# self.mysql_user = mysql_user
|
|
42
|
+
# self.mysql_password = mysql_password
|
|
43
|
+
# self.mysql_db = mysql_db
|
|
44
|
+
# self.connection = None
|
|
45
|
+
#
|
|
46
|
+
# @classmethod
|
|
47
|
+
# def from_settings(cls, settings):
|
|
48
|
+
# return cls(
|
|
49
|
+
# mysql_uri=settings.get('MYSQL_HOST'),
|
|
50
|
+
# mysql_user=settings.get('MYSQL_USER'),
|
|
51
|
+
# mysql_password=settings.get('MYSQL_PASSWORD'),
|
|
52
|
+
# mysql_db=settings.get('MYSQL_DB')
|
|
53
|
+
# )
|
|
54
|
+
#
|
|
55
|
+
# def open_spider(self, spider):
|
|
56
|
+
# self.connection = pymysql.connect(...)
|
|
57
|
+
#
|
|
58
|
+
# def close_spider(self, spider):
|
|
59
|
+
# if self.connection:
|
|
60
|
+
# self.connection.close()
|
|
61
|
+
#
|
|
62
|
+
# def process_item(self, item, spider):
|
|
63
|
+
# # 执行 SQL 插入
|
|
64
64
|
# return item
|
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
# -*- coding: UTF-8 -*-
|
|
2
|
-
"""自动创建的 settings.py 文件"""
|
|
3
|
-
|
|
4
|
-
PROJECT_NAME = '{{project_name}}'
|
|
5
|
-
VERSION = '1.0'
|
|
6
|
-
|
|
7
|
-
# ============================== 网络请求配置 ==============================
|
|
8
|
-
DOWNLOADER = "crawlo.downloader.aiohttp_downloader.AioHttpDownloader"
|
|
9
|
-
DOWNLOAD_TIMEOUT = 60
|
|
10
|
-
VERIFY_SSL = True
|
|
11
|
-
USE_SESSION = True
|
|
12
|
-
|
|
13
|
-
DOWNLOAD_DELAY = 1.0
|
|
14
|
-
RANDOMNESS = True
|
|
15
|
-
|
|
16
|
-
MAX_RETRY_TIMES = 3
|
|
17
|
-
RETRY_HTTP_CODES = [408, 429, 500, 502, 503, 504, 522, 524]
|
|
18
|
-
IGNORE_HTTP_CODES = [403, 404]
|
|
19
|
-
|
|
20
|
-
CONNECTION_POOL_LIMIT = 100
|
|
21
|
-
|
|
22
|
-
# ============================== 并发与调度 ==============================
|
|
23
|
-
CONCURRENCY = 8
|
|
24
|
-
MAX_RUNNING_SPIDERS = 3
|
|
25
|
-
|
|
26
|
-
# ============================== 数据存储 ==============================
|
|
27
|
-
MYSQL_HOST = '127.0.0.1'
|
|
28
|
-
MYSQL_PORT = 3306
|
|
29
|
-
MYSQL_USER = 'root'
|
|
30
|
-
MYSQL_PASSWORD = '123456'
|
|
31
|
-
MYSQL_DB = '{{project_name}}'
|
|
32
|
-
MYSQL_TABLE = 'crawled_data'
|
|
33
|
-
|
|
34
|
-
# ============================== 去重过滤 ==============================
|
|
35
|
-
FILTER_CLASS = 'crawlo.filters.memory_filter.MemoryFilter'
|
|
36
|
-
|
|
37
|
-
# ============================== 中间件 & 管道 ==============================
|
|
38
|
-
MIDDLEWARES = [
|
|
39
|
-
'crawlo.middleware.request_ignore.RequestIgnoreMiddleware',
|
|
40
|
-
'crawlo.middleware.download_delay.DownloadDelayMiddleware',
|
|
41
|
-
'crawlo.middleware.default_header.DefaultHeaderMiddleware',
|
|
42
|
-
'crawlo.middleware.proxy.ProxyMiddleware',
|
|
43
|
-
'crawlo.middleware.retry.RetryMiddleware',
|
|
44
|
-
'crawlo.middleware.response_code.ResponseCodeMiddleware',
|
|
45
|
-
'crawlo.middleware.response_filter.ResponseFilterMiddleware',
|
|
46
|
-
]
|
|
47
|
-
|
|
48
|
-
PIPELINES = [
|
|
49
|
-
'crawlo.pipelines.console_pipeline.ConsolePipeline',
|
|
50
|
-
]
|
|
51
|
-
|
|
52
|
-
# ============================== 日志 ==============================
|
|
53
|
-
LOG_LEVEL = 'INFO'
|
|
54
|
-
LOG_FILE = f'logs/{{{
|
|
1
|
+
# -*- coding: UTF-8 -*-
|
|
2
|
+
"""自动创建的 settings.py 文件"""
|
|
3
|
+
|
|
4
|
+
PROJECT_NAME = '{{project_name}}'
|
|
5
|
+
VERSION = '1.0'
|
|
6
|
+
|
|
7
|
+
# ============================== 网络请求配置 ==============================
|
|
8
|
+
DOWNLOADER = "crawlo.downloader.aiohttp_downloader.AioHttpDownloader"
|
|
9
|
+
DOWNLOAD_TIMEOUT = 60
|
|
10
|
+
VERIFY_SSL = True
|
|
11
|
+
USE_SESSION = True
|
|
12
|
+
|
|
13
|
+
DOWNLOAD_DELAY = 1.0
|
|
14
|
+
RANDOMNESS = True
|
|
15
|
+
|
|
16
|
+
MAX_RETRY_TIMES = 3
|
|
17
|
+
RETRY_HTTP_CODES = [408, 429, 500, 502, 503, 504, 522, 524]
|
|
18
|
+
IGNORE_HTTP_CODES = [403, 404]
|
|
19
|
+
|
|
20
|
+
CONNECTION_POOL_LIMIT = 100
|
|
21
|
+
|
|
22
|
+
# ============================== 并发与调度 ==============================
|
|
23
|
+
CONCURRENCY = 8
|
|
24
|
+
MAX_RUNNING_SPIDERS = 3
|
|
25
|
+
|
|
26
|
+
# ============================== 数据存储 ==============================
|
|
27
|
+
MYSQL_HOST = '127.0.0.1'
|
|
28
|
+
MYSQL_PORT = 3306
|
|
29
|
+
MYSQL_USER = 'root'
|
|
30
|
+
MYSQL_PASSWORD = '123456'
|
|
31
|
+
MYSQL_DB = '{{project_name}}'
|
|
32
|
+
MYSQL_TABLE = 'crawled_data'
|
|
33
|
+
|
|
34
|
+
# ============================== 去重过滤 ==============================
|
|
35
|
+
FILTER_CLASS = 'crawlo.filters.memory_filter.MemoryFilter'
|
|
36
|
+
|
|
37
|
+
# ============================== 中间件 & 管道 ==============================
|
|
38
|
+
MIDDLEWARES = [
|
|
39
|
+
'crawlo.middleware.request_ignore.RequestIgnoreMiddleware',
|
|
40
|
+
'crawlo.middleware.download_delay.DownloadDelayMiddleware',
|
|
41
|
+
'crawlo.middleware.default_header.DefaultHeaderMiddleware',
|
|
42
|
+
'crawlo.middleware.proxy.ProxyMiddleware',
|
|
43
|
+
'crawlo.middleware.retry.RetryMiddleware',
|
|
44
|
+
'crawlo.middleware.response_code.ResponseCodeMiddleware',
|
|
45
|
+
'crawlo.middleware.response_filter.ResponseFilterMiddleware',
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
PIPELINES = [
|
|
49
|
+
'crawlo.pipelines.console_pipeline.ConsolePipeline',
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
# ============================== 日志 ==============================
|
|
53
|
+
LOG_LEVEL = 'INFO'
|
|
54
|
+
LOG_FILE = f'logs/{{{project_name}}}.log'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# -*- coding: UTF-8 -*-
|
|
2
|
-
"""
|
|
3
|
-
{{project_name}}.spiders
|
|
4
|
-
========================
|
|
5
|
-
存放所有的爬虫。
|
|
1
|
+
# -*- coding: UTF-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
{{project_name}}.spiders
|
|
4
|
+
========================
|
|
5
|
+
存放所有的爬虫。
|
|
6
6
|
"""
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
# -*- coding: UTF-8 -*-
|
|
2
|
-
"""
|
|
3
|
-
{{project_name}}.spiders.{{spider_name}}
|
|
4
|
-
=======================================
|
|
5
|
-
由 `crawlo genspider` 命令生成的爬虫。
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
from crawlo.spider import Spider
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class {{class_name}}(Spider):
|
|
12
|
-
"""
|
|
13
|
-
爬虫:{{spider_name}}
|
|
14
|
-
"""
|
|
15
|
-
name = '{{spider_name}}'
|
|
16
|
-
allowed_domains = ['{{domain}}']
|
|
17
|
-
start_urls = ['https://{{domain}}/']
|
|
18
|
-
|
|
19
|
-
def parse(self, response):
|
|
20
|
-
"""
|
|
21
|
-
解析响应的主方法。
|
|
22
|
-
"""
|
|
23
|
-
# TODO: 在这里编写你的解析逻辑
|
|
24
|
-
|
|
25
|
-
# 示例:提取数据
|
|
26
|
-
# item = {{item_class}}()
|
|
27
|
-
# item['title'] = response.xpath('//title/text()').get()
|
|
28
|
-
# yield item
|
|
29
|
-
|
|
30
|
-
# 示例:提取链接并跟进
|
|
31
|
-
# for href in response.xpath('//a/@href').getall():
|
|
1
|
+
# -*- coding: UTF-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
{{project_name}}.spiders.{{spider_name}}
|
|
4
|
+
=======================================
|
|
5
|
+
由 `crawlo genspider` 命令生成的爬虫。
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from crawlo.spider import Spider
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class {{class_name}}(Spider):
|
|
12
|
+
"""
|
|
13
|
+
爬虫:{{spider_name}}
|
|
14
|
+
"""
|
|
15
|
+
name = '{{spider_name}}'
|
|
16
|
+
allowed_domains = ['{{domain}}']
|
|
17
|
+
start_urls = ['https://{{domain}}/']
|
|
18
|
+
|
|
19
|
+
def parse(self, response):
|
|
20
|
+
"""
|
|
21
|
+
解析响应的主方法。
|
|
22
|
+
"""
|
|
23
|
+
# TODO: 在这里编写你的解析逻辑
|
|
24
|
+
|
|
25
|
+
# 示例:提取数据
|
|
26
|
+
# item = {{item_class}}()
|
|
27
|
+
# item['title'] = response.xpath('//title/text()').get()
|
|
28
|
+
# yield item
|
|
29
|
+
|
|
30
|
+
# 示例:提取链接并跟进
|
|
31
|
+
# for href in response.xpath('//a/@href').getall():
|
|
32
32
|
# yield response.follow(href, callback=self.parse)
|
crawlo/utils/__init__.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
#!/usr/bin/python
|
|
2
|
-
# -*- coding:UTF-8 -*-
|
|
3
|
-
"""
|
|
4
|
-
# @Time : 2025-02-05 13:57
|
|
5
|
-
# @Author : oscar
|
|
6
|
-
# @Desc : None
|
|
7
|
-
"""
|
|
1
|
+
#!/usr/bin/python
|
|
2
|
+
# -*- coding:UTF-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
# @Time : 2025-02-05 13:57
|
|
5
|
+
# @Author : oscar
|
|
6
|
+
# @Desc : None
|
|
7
|
+
"""
|