cobweb-launcher 1.1.13__py3-none-any.whl → 1.1.15__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.
- cobweb/crawlers/base_crawler.py +65 -60
- cobweb/launchers/launcher.py +1 -1
- cobweb/launchers/launcher_pro.py +1 -1
- {cobweb_launcher-1.1.13.dist-info → cobweb_launcher-1.1.15.dist-info}/METADATA +1 -1
- {cobweb_launcher-1.1.13.dist-info → cobweb_launcher-1.1.15.dist-info}/RECORD +8 -8
- {cobweb_launcher-1.1.13.dist-info → cobweb_launcher-1.1.15.dist-info}/LICENSE +0 -0
- {cobweb_launcher-1.1.13.dist-info → cobweb_launcher-1.1.15.dist-info}/WHEEL +0 -0
- {cobweb_launcher-1.1.13.dist-info → cobweb_launcher-1.1.15.dist-info}/top_level.txt +0 -0
cobweb/crawlers/base_crawler.py
CHANGED
|
@@ -32,7 +32,7 @@ class Crawler(threading.Thread):
|
|
|
32
32
|
@staticmethod
|
|
33
33
|
def request(seed: Seed) -> Union[Request, BaseItem]:
|
|
34
34
|
stream = True if setting.DOWNLOAD_MODEL else False
|
|
35
|
-
|
|
35
|
+
yield Request(seed.url, seed, stream=stream, timeout=5)
|
|
36
36
|
|
|
37
37
|
@staticmethod
|
|
38
38
|
def download(item: Request) -> Union[Seed, BaseItem, Response, str]:
|
|
@@ -43,12 +43,27 @@ class Crawler(threading.Thread):
|
|
|
43
43
|
def parse(item: Response) -> BaseItem:
|
|
44
44
|
pass
|
|
45
45
|
|
|
46
|
-
def
|
|
46
|
+
def get_seed(self) -> Seed:
|
|
47
47
|
return self.launcher_queue['todo'].pop()
|
|
48
48
|
|
|
49
|
+
def distribute(self, item, seed):
|
|
50
|
+
if isinstance(item, BaseItem):
|
|
51
|
+
self.upload_queue.push(item)
|
|
52
|
+
elif isinstance(item, Seed):
|
|
53
|
+
self.launcher_queue['new'].push(item)
|
|
54
|
+
elif isinstance(item, str) and item == DealModel.poll:
|
|
55
|
+
self.launcher_queue['todo'].push(seed)
|
|
56
|
+
elif isinstance(item, str) and item == DealModel.done:
|
|
57
|
+
self.launcher_queue['done'].push(seed)
|
|
58
|
+
elif isinstance(item, str) and item == DealModel.fail:
|
|
59
|
+
seed.identifier = DealModel.fail
|
|
60
|
+
self.launcher_queue['done'].push(seed)
|
|
61
|
+
else:
|
|
62
|
+
raise TypeError("yield value type error!")
|
|
63
|
+
|
|
49
64
|
def spider(self):
|
|
50
65
|
while True:
|
|
51
|
-
seed = self.
|
|
66
|
+
seed = self.get_seed()
|
|
52
67
|
|
|
53
68
|
if not seed:
|
|
54
69
|
continue
|
|
@@ -58,63 +73,53 @@ class Crawler(threading.Thread):
|
|
|
58
73
|
self.launcher_queue['done'].push(seed)
|
|
59
74
|
continue
|
|
60
75
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
self.
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
logger.info(LogTemplate.download_exception.format(
|
|
109
|
-
detail=seed_detail_log_info, retry=seed.params.retry,
|
|
110
|
-
priority=seed.params.priority, seed_version=seed.params.seed_version,
|
|
111
|
-
identifier=seed.identifier or "", exception=e
|
|
112
|
-
))
|
|
113
|
-
seed.params.retry += 1
|
|
114
|
-
self.launcher_queue['todo'].push(seed)
|
|
115
|
-
|
|
116
|
-
elif isinstance(item, BaseItem):
|
|
117
|
-
self.upload_queue.push(item)
|
|
76
|
+
seed_detail_log_info = download_log_info(seed.to_dict)
|
|
77
|
+
|
|
78
|
+
try:
|
|
79
|
+
request_iterators = self.request(seed)
|
|
80
|
+
|
|
81
|
+
if not isgenerator(request_iterators):
|
|
82
|
+
raise TypeError("request function isn't a generator!")
|
|
83
|
+
|
|
84
|
+
for request_item in request_iterators:
|
|
85
|
+
|
|
86
|
+
if isinstance(request_item, BaseItem):
|
|
87
|
+
self.upload_queue.push(request_item)
|
|
88
|
+
|
|
89
|
+
elif isinstance(request_item, Request):
|
|
90
|
+
download_iterators = self.download(request_item)
|
|
91
|
+
if not isgenerator(download_iterators):
|
|
92
|
+
raise TypeError("download function isn't a generator")
|
|
93
|
+
for download_item in download_iterators:
|
|
94
|
+
if isinstance(download_item, Response):
|
|
95
|
+
logger.info(LogTemplate.download_info.format(
|
|
96
|
+
detail=seed_detail_log_info,
|
|
97
|
+
retry=seed.params.retry,
|
|
98
|
+
priority=seed.params.priority,
|
|
99
|
+
seed_version=seed.params.seed_version,
|
|
100
|
+
identifier=seed.identifier or "",
|
|
101
|
+
status=download_item.response,
|
|
102
|
+
response=download_log_info(download_item.to_dict)
|
|
103
|
+
))
|
|
104
|
+
parse_iterators = self.parse(download_item)
|
|
105
|
+
if not isgenerator(parse_iterators):
|
|
106
|
+
raise TypeError("parse function isn't a generator")
|
|
107
|
+
for parse_item in parse_iterators:
|
|
108
|
+
if isinstance(parse_item, Response):
|
|
109
|
+
raise TypeError("upload_item can't be a Response instance")
|
|
110
|
+
self.distribute(parse_item, seed)
|
|
111
|
+
else:
|
|
112
|
+
self.distribute(download_item, seed)
|
|
113
|
+
except Exception as e:
|
|
114
|
+
logger.info(LogTemplate.download_exception.format(
|
|
115
|
+
detail=seed_detail_log_info,
|
|
116
|
+
retry=seed.params.retry,
|
|
117
|
+
priority=seed.params.priority,
|
|
118
|
+
seed_version=seed.params.seed_version,
|
|
119
|
+
identifier=seed.identifier or "", exception=e
|
|
120
|
+
))
|
|
121
|
+
seed.params.retry += 1
|
|
122
|
+
self.launcher_queue['todo'].push(seed)
|
|
118
123
|
|
|
119
124
|
def run(self):
|
|
120
125
|
for index in range(self.spider_thread_num):
|
cobweb/launchers/launcher.py
CHANGED
cobweb/launchers/launcher_pro.py
CHANGED
|
@@ -117,7 +117,7 @@ class LauncherPro(Launcher):
|
|
|
117
117
|
seed = self.__LAUNCHER_QUEUE__['done'].pop()
|
|
118
118
|
if not seed:
|
|
119
119
|
break
|
|
120
|
-
if seed.
|
|
120
|
+
if seed.identifier == DealModel.fail:
|
|
121
121
|
f_seeds.append(seed.to_string)
|
|
122
122
|
elif self._done_model == 1:
|
|
123
123
|
s_seeds.append(seed.to_string)
|
|
@@ -10,23 +10,23 @@ cobweb/base/request.py,sha256=tEkgMVUfdQI-kZuzWuiit9P_q4Q9-_RZh9aXXpc0314,2352
|
|
|
10
10
|
cobweb/base/response.py,sha256=eB1DWMXFCpn3cJ3yzgCRU1WeZAdayGDohRgdjdMUFN4,406
|
|
11
11
|
cobweb/base/seed.py,sha256=QxlXztWjV8VvcHu-cTzyoDHaDvoX26iyoJKiWk64HnE,2759
|
|
12
12
|
cobweb/crawlers/__init__.py,sha256=Rr3DTjD-abMA1_FYcQJZYNvQvcWMuEVcsIU6duqHrw4,75
|
|
13
|
-
cobweb/crawlers/base_crawler.py,sha256=
|
|
13
|
+
cobweb/crawlers/base_crawler.py,sha256=G5qMeTDgoBNQ9DGzWuFmMM4C9KJvGWxptLHeSgiWZrI,5181
|
|
14
14
|
cobweb/crawlers/file_crawler.py,sha256=2Sjbdgxzqd41WykKUQE3QQlGai3T8k-pmHNmPlTchjQ,4454
|
|
15
15
|
cobweb/db/__init__.py,sha256=ut0iEyBLjcJL06WNG_5_d4hO5PJWvDrKWMkDOdmgh2M,30
|
|
16
16
|
cobweb/db/redis_db.py,sha256=NNI2QkRV1hEZI-z-COEncXt88z3pZN6wusKlcQzc8V4,4304
|
|
17
17
|
cobweb/exceptions/__init__.py,sha256=E9SHnJBbhD7fOgPFMswqyOf8SKRDrI_i25L0bSpohvk,32
|
|
18
18
|
cobweb/exceptions/oss_db_exception.py,sha256=iP_AImjNHT3-Iv49zCFQ3rdLnlvuHa3h2BXApgrOYpA,636
|
|
19
19
|
cobweb/launchers/__init__.py,sha256=qwlkEJVri7dvCgi45aX3lqAmQS0HrPicAipDvH75kew,69
|
|
20
|
-
cobweb/launchers/launcher.py,sha256=
|
|
21
|
-
cobweb/launchers/launcher_pro.py,sha256=
|
|
20
|
+
cobweb/launchers/launcher.py,sha256=LQdlpaF4fafEX01_3B9CB6hD-6YMPag6QOGl9rDprNE,5707
|
|
21
|
+
cobweb/launchers/launcher_pro.py,sha256=20o-Yd_JAdzJPchpilCtCd61hrf90LKkxXcCjm2azhQ,6586
|
|
22
22
|
cobweb/pipelines/__init__.py,sha256=xanY-Z1d7zRR5JhCdW2htzrAywnKBkigiaUlTFa6of0,80
|
|
23
23
|
cobweb/pipelines/base_pipeline.py,sha256=fYnWf79GmhufXpcnMa3te18SbmnVeYLwxfyo-zLd9CY,1577
|
|
24
24
|
cobweb/pipelines/loghub_pipeline.py,sha256=cjPO6w6UJ0jNw2fVvdX0BCdlm58T7dmYXlxzXOBpvfY,1027
|
|
25
25
|
cobweb/utils/__init__.py,sha256=JTE4sBfHnKHhD6w9Auk0MIT7O9BMOamCeryhlHNx3Zg,47
|
|
26
26
|
cobweb/utils/oss.py,sha256=qAl05ybL2Jp6KFjHDHVMfmeBHQmDKPtZleHjHAY7LZc,3277
|
|
27
27
|
cobweb/utils/tools.py,sha256=bVd3iRGBvwhohQAH7AXTTjbmQ54Z35K0O-fatEyhePU,1249
|
|
28
|
-
cobweb_launcher-1.1.
|
|
29
|
-
cobweb_launcher-1.1.
|
|
30
|
-
cobweb_launcher-1.1.
|
|
31
|
-
cobweb_launcher-1.1.
|
|
32
|
-
cobweb_launcher-1.1.
|
|
28
|
+
cobweb_launcher-1.1.15.dist-info/LICENSE,sha256=z1rxSIGOyzcSb3orZxFPxzx-0C1vTocmswqBNxpKfEk,1063
|
|
29
|
+
cobweb_launcher-1.1.15.dist-info/METADATA,sha256=HbjhwAL_1dC-JO4nhJstX3dXG_c5nGweYZ0U9EZWk3w,1246
|
|
30
|
+
cobweb_launcher-1.1.15.dist-info/WHEEL,sha256=ewwEueio1C2XeHTvT17n8dZUJgOvyCWCt0WVNLClP9o,92
|
|
31
|
+
cobweb_launcher-1.1.15.dist-info/top_level.txt,sha256=4GETBGNsKqiCUezmT-mJn7tjhcDlu7nLIV5gGgHBW4I,7
|
|
32
|
+
cobweb_launcher-1.1.15.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|