@crawlee/basic 3.0.0-alpha.2 → 3.0.0-alpha.3

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,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2018 Apify Technologies s.r.o.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
File without changes
@@ -0,0 +1,4 @@
1
+ export * from '@crawlee/core';
2
+ export * from './internals/basic-crawler';
3
+ export * from './internals/constants';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC"}
File without changes
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,wDAA8B;AAC9B,oEAA0C;AAC1C,gEAAsC"}
@@ -0,0 +1,379 @@
1
+ import { Log } from '@apify/log';
2
+ import { AutoscaledPool, AutoscaledPoolOptions, EnqueueLinksOptions, CrawlerHandleFailedRequestInput, ProxyInfo, QueueOperationInfo, Request, RequestList, RequestQueue, Session, SessionPool, SessionPoolOptions, Statistics, type CrawlingContext, RequestOptions, RequestQueueOperationOptions, Configuration, EventManager, FinalStatistics } from '@crawlee/core';
3
+ import { Awaitable } from '@crawlee/utils';
4
+ export interface BasicCrawlerCrawlingContext extends CrawlingContext {
5
+ crawler: BasicCrawler;
6
+ enqueueLinks: (options: BasicCrawlerEnqueueLinksOptions) => Promise<QueueOperationInfo[]>;
7
+ }
8
+ export interface BasicCrawlerHandleFailedRequestInput extends CrawlerHandleFailedRequestInput {
9
+ crawler: BasicCrawler;
10
+ }
11
+ /** @internal */
12
+ export declare type BasicCrawlerEnqueueLinksOptions = Omit<EnqueueLinksOptions, 'requestQueue'>;
13
+ export declare type RequestHandler<Context extends CrawlingContext = BasicCrawlerCrawlingContext> = (inputs: Context) => Awaitable<void>;
14
+ export declare type FailedRequestHandler<Inputs extends CrawlerHandleFailedRequestInput = BasicCrawlerHandleFailedRequestInput> = (inputs: Inputs) => Awaitable<void>;
15
+ export interface BasicCrawlerOptions<Context extends CrawlingContext = BasicCrawlerCrawlingContext, ErrorContext extends CrawlerHandleFailedRequestInput = BasicCrawlerHandleFailedRequestInput> {
16
+ /**
17
+ * User-provided function that performs the logic of the crawler. It is called for each URL to crawl.
18
+ *
19
+ * The function receives the following object as an argument:
20
+ * ```
21
+ * {
22
+ * request: Request,
23
+ * session: Session,
24
+ * crawler: BasicCrawler,
25
+ * }
26
+ * ```
27
+ * where the {@link Request} instance represents the URL to crawl.
28
+ *
29
+ * The function must return a promise, which is then awaited by the crawler.
30
+ *
31
+ * If the function throws an exception, the crawler will try to re-crawl the
32
+ * request later, up to `option.maxRequestRetries` times.
33
+ * If all the retries fail, the crawler calls the function
34
+ * provided to the `handleFailedRequestFunction` parameter.
35
+ * To make this work, you should **always**
36
+ * let your function throw exceptions rather than catch them.
37
+ * The exceptions are logged to the request using the
38
+ * {@link Request.pushErrorMessage} function.
39
+ */
40
+ requestHandler: RequestHandler<Context>;
41
+ /**
42
+ * User-provided function that performs the logic of the crawler. It is called for each URL to crawl.
43
+ *
44
+ * The function receives the following object as an argument:
45
+ * ```
46
+ * {
47
+ * request: Request,
48
+ * session: Session,
49
+ * crawler: BasicCrawler,
50
+ * }
51
+ * ```
52
+ * where the {@link Request} instance represents the URL to crawl.
53
+ *
54
+ * The function must return a promise, which is then awaited by the crawler.
55
+ *
56
+ * If the function throws an exception, the crawler will try to re-crawl the
57
+ * request later, up to `option.maxRequestRetries` times.
58
+ * If all the retries fail, the crawler calls the function
59
+ * provided to the `handleFailedRequestFunction` parameter.
60
+ * To make this work, you should **always**
61
+ * let your function throw exceptions rather than catch them.
62
+ * The exceptions are logged to the request using the
63
+ * {@link Request.pushErrorMessage} function.
64
+ *
65
+ * @deprecated `handleRequestFunction` has been renamed to `requestHandler` and will be removed in a future version.
66
+ */
67
+ handleRequestFunction?: RequestHandler<Context>;
68
+ /**
69
+ * Static list of URLs to be processed.
70
+ * Either `requestList` or `requestQueue` option must be provided (or both).
71
+ */
72
+ requestList?: RequestList;
73
+ /**
74
+ * Dynamic queue of URLs to be processed. This is useful for recursive crawling of websites.
75
+ * Either `requestList` or `requestQueue` option must be provided (or both).
76
+ */
77
+ requestQueue?: RequestQueue;
78
+ /**
79
+ * Timeout in which the function passed as `requestHandler` needs to finish, in seconds.
80
+ * @default 60
81
+ */
82
+ requestHandlerTimeoutSecs?: number;
83
+ /**
84
+ * Timeout in which the function passed as `requestHandler` needs to finish, in seconds.
85
+ * @default 60
86
+ * @deprecated `handleRequestTimeoutSecs` has been renamed to `requestHandlerTimeoutSecs` and will be removed in a future version.
87
+ */
88
+ handleRequestTimeoutSecs?: number;
89
+ /**
90
+ * A function to handle requests that failed more than `option.maxRequestRetries` times.
91
+ *
92
+ * The function receives the following object as an argument:
93
+ * ```
94
+ * {
95
+ * request: Request,
96
+ * error: Error,
97
+ * session: Session,
98
+ * crawler: BasicCrawler,
99
+ * }
100
+ * ```
101
+ * where the {@link Request} instance corresponds to the failed request, and the `Error` instance
102
+ * represents the last error thrown during processing of the request.
103
+ *
104
+ * See
105
+ * [source code](https://github.com/apify/apify-js/blob/master/src/crawlers/basic_crawler.js#L11)
106
+ * for the default implementation of this function.
107
+ */
108
+ failedRequestHandler?: FailedRequestHandler<ErrorContext>;
109
+ /**
110
+ * A function to handle requests that failed more than `option.maxRequestRetries` times.
111
+ *
112
+ * The function receives the following object as an argument:
113
+ * ```
114
+ * {
115
+ * request: Request,
116
+ * error: Error,
117
+ * session: Session,
118
+ * crawler: BasicCrawler,
119
+ * }
120
+ * ```
121
+ * where the {@link Request} instance corresponds to the failed request, and the `Error` instance
122
+ * represents the last error thrown during processing of the request.
123
+ *
124
+ * See
125
+ * [source code](https://github.com/apify/apify-js/blob/master/src/crawlers/basic_crawler.js#L11)
126
+ * for the default implementation of this function.
127
+ *
128
+ * @deprecated `handleFailedRequestFunction` has been renamed to `failedRequestHandler` and will be removed in a future version.
129
+ */
130
+ handleFailedRequestFunction?: FailedRequestHandler<ErrorContext>;
131
+ /**
132
+ * Indicates how many times the request is retried if {@link requestHandler} or {@link handlePageFunction} fails.
133
+ * @default 3
134
+ */
135
+ maxRequestRetries?: number;
136
+ /**
137
+ * Maximum number of pages that the crawler will open. The crawl will stop when this limit is reached.
138
+ * Always set this value in order to prevent infinite loops in misconfigured crawlers.
139
+ * Note that in cases of parallel crawling, the actual number of pages visited might be slightly higher than this value.
140
+ */
141
+ maxRequestsPerCrawl?: number;
142
+ /**
143
+ * Custom options passed to the underlying {@link AutoscaledPool} constructor.
144
+ * Note that the `runTaskFunction` and `isTaskReadyFunction` options
145
+ * are provided by the crawler and cannot be overridden.
146
+ * However, you can provide a custom implementation of `isFinishedFunction`.
147
+ */
148
+ autoscaledPoolOptions?: AutoscaledPoolOptions;
149
+ /**
150
+ * Sets the minimum concurrency (parallelism) for the crawl. Shortcut to the corresponding {@link AutoscaledPool} option.
151
+ *
152
+ * *WARNING:* If you set this value too high with respect to the available system memory and CPU, your crawler will run extremely slow or crash.
153
+ * If you're not sure, just keep the default value and the concurrency will scale up automatically.
154
+ */
155
+ minConcurrency?: number;
156
+ /**
157
+ * Sets the maximum concurrency (parallelism) for the crawl. Shortcut to the corresponding {@link AutoscaledPool} option.
158
+ */
159
+ maxConcurrency?: number;
160
+ /**
161
+ * Basic crawler will initialize the {@link SessionPool} with the corresponding `sessionPoolOptions`.
162
+ * The session instance will be than available in the `handleRequestFunction`.
163
+ */
164
+ useSessionPool?: boolean;
165
+ /**
166
+ * The configuration options for {@link SessionPool} to use.
167
+ */
168
+ sessionPoolOptions?: SessionPoolOptions;
169
+ /** @internal */
170
+ log?: Log;
171
+ }
172
+ /**
173
+ * Provides a simple framework for parallel crawling of web pages.
174
+ * The URLs to crawl are fed either from a static list of URLs
175
+ * or from a dynamic queue of URLs enabling recursive crawling of websites.
176
+ *
177
+ * `BasicCrawler` is a low-level tool that requires the user to implement the page
178
+ * download and data extraction functionality themselves.
179
+ * If you want a crawler that already facilitates this functionality,
180
+ * please consider using {@link CheerioCrawler}, {@link PuppeteerCrawler} or {@link PlaywrightCrawler}.
181
+ *
182
+ * `BasicCrawler` invokes the user-provided {@link BasicCrawlerOptions.requestHandler}
183
+ * for each {@link Request} object, which represents a single URL to crawl.
184
+ * The {@link Request} objects are fed from the {@link RequestList} or the {@link RequestQueue}
185
+ * instances provided by the {@link BasicCrawlerOptions.requestList} or {@link BasicCrawlerOptions.requestQueue}
186
+ * constructor options, respectively.
187
+ *
188
+ * If both {@link BasicCrawlerOptions.requestList} and {@link BasicCrawlerOptions.requestQueue} options are used,
189
+ * the instance first processes URLs from the {@link RequestList} and automatically enqueues all of them
190
+ * to {@link RequestQueue} before it starts their processing. This ensures that a single URL is not crawled multiple times.
191
+ *
192
+ * The crawler finishes if there are no more {@link Request} objects to crawl.
193
+ *
194
+ * New requests are only dispatched when there is enough free CPU and memory available,
195
+ * using the functionality provided by the {@link AutoscaledPool} class.
196
+ * All {@link AutoscaledPool} configuration options can be passed to the `autoscaledPoolOptions`
197
+ * parameter of the `BasicCrawler` constructor. For user convenience, the `minConcurrency` and `maxConcurrency`
198
+ * {@link AutoscaledPool} options are available directly in the `BasicCrawler` constructor.
199
+ *
200
+ * **Example usage:**
201
+ *
202
+ * ```javascript
203
+ * const { gotScraping } = require('got-scraping');
204
+ *
205
+ * // Prepare a list of URLs to crawl
206
+ * const requestList = new RequestList({
207
+ * sources: [
208
+ * { url: 'http://www.example.com/page-1' },
209
+ * { url: 'http://www.example.com/page-2' },
210
+ * ],
211
+ * });
212
+ * await requestList.initialize();
213
+ *
214
+ * // Crawl the URLs
215
+ * const crawler = new BasicCrawler({
216
+ * requestList,
217
+ * handleRequestFunction: async ({ request }) => {
218
+ * // 'request' contains an instance of the Request class
219
+ * // Here we simply fetch the HTML of the page and store it to a dataset
220
+ * const { body } = await gotScraping({
221
+ * url: request.url,
222
+ * method: request.method,
223
+ * body: request.payload,
224
+ * headers: request.headers,
225
+ * });
226
+ *
227
+ * await Actor.pushData({
228
+ * url: request.url,
229
+ * html: body,
230
+ * })
231
+ * },
232
+ * });
233
+ *
234
+ * await crawler.run();
235
+ * ```
236
+ * @category Crawlers
237
+ */
238
+ export declare class BasicCrawler<Context extends CrawlingContext = BasicCrawlerCrawlingContext, ErrorContext extends CrawlerHandleFailedRequestInput = BasicCrawlerHandleFailedRequestInput> {
239
+ readonly config: Configuration;
240
+ /**
241
+ * Static list of URLs to be processed.
242
+ */
243
+ readonly stats: Statistics;
244
+ /**
245
+ * A reference to the underlying {@link RequestList} class that manages the crawler's {@link Request}s.
246
+ * Either `requestList` or `requestQueue` option must be provided (or both).
247
+ * Only available if used by the crawler.
248
+ */
249
+ requestList?: RequestList;
250
+ /**
251
+ * Dynamic queue of URLs to be processed. This is useful for recursive crawling of websites.
252
+ * A reference to the underlying {@link RequestQueue} class that manages the crawler's {@link Request}s.
253
+ * Either `requestList` or `requestQueue` option must be provided (or both).
254
+ * Only available if used by the crawler.
255
+ */
256
+ requestQueue?: RequestQueue;
257
+ /**
258
+ * A reference to the underlying {@link SessionPool} class that manages the crawler's {@link Session}s.
259
+ * Only available if used by the crawler.
260
+ */
261
+ sessionPool?: SessionPool;
262
+ /**
263
+ * A reference to the underlying {@link AutoscaledPool} class that manages the concurrency of the crawler.
264
+ * Note that this property is only initialized after calling the {@link BasicCrawler.run} function.
265
+ * You can use it to change the concurrency settings on the fly,
266
+ * to pause the crawler by calling {@link AutoscaledPool.pause}
267
+ * or to abort it by calling {@link AutoscaledPool.abort}.
268
+ */
269
+ autoscaledPool?: AutoscaledPool;
270
+ protected log: Log;
271
+ protected requestHandler: RequestHandler<Context>;
272
+ protected failedRequestHandler?: FailedRequestHandler<ErrorContext>;
273
+ protected requestHandlerTimeoutMillis: number;
274
+ protected internalTimeoutMillis: number;
275
+ protected maxRequestRetries: number;
276
+ protected handledRequestsCount: number;
277
+ protected sessionPoolOptions: SessionPoolOptions;
278
+ protected useSessionPool: boolean;
279
+ protected crawlingContexts: Map<string, Context>;
280
+ protected autoscaledPoolOptions: AutoscaledPoolOptions;
281
+ protected events: EventManager;
282
+ protected static optionsShape: {
283
+ requestList: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
284
+ requestQueue: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
285
+ requestHandler: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
286
+ handleRequestFunction: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
287
+ requestHandlerTimeoutSecs: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
288
+ handleRequestTimeoutSecs: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
289
+ failedRequestHandler: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
290
+ handleFailedRequestFunction: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
291
+ maxRequestRetries: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
292
+ maxRequestsPerCrawl: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
293
+ autoscaledPoolOptions: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
294
+ sessionPoolOptions: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
295
+ useSessionPool: import("ow").BooleanPredicate & import("ow").BasePredicate<boolean | undefined>;
296
+ minConcurrency: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
297
+ maxConcurrency: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
298
+ log: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
299
+ };
300
+ /**
301
+ * All `BasicCrawler` parameters are passed via an options object.
302
+ */
303
+ constructor(options: BasicCrawlerOptions<Context, ErrorContext>, config?: Configuration);
304
+ /**
305
+ * Runs the crawler. Returns a promise that gets resolved once all the requests are processed.
306
+ */
307
+ run(): Promise<FinalStatistics>;
308
+ getRequestQueue(): Promise<RequestQueue>;
309
+ /**
310
+ * Adds requests to be processed by the crawler
311
+ * @param requests The requests to add
312
+ * @param options Options for the request queue
313
+ */
314
+ addRequests(requests: (string | Request | RequestOptions)[], options?: RequestQueueOperationOptions): Promise<import("packages/core/dist/storages/storage").BatchAddRequestsResult>;
315
+ protected _init(): Promise<void>;
316
+ protected _runRequestHandler(crawlingContext: Context): Promise<void>;
317
+ protected _pauseOnMigration(): Promise<void>;
318
+ /**
319
+ * Fetches request from either RequestList or RequestQueue. If request comes from a RequestList
320
+ * and RequestQueue is present then enqueues it to the queue first.
321
+ */
322
+ protected _fetchNextRequest(): Promise<Request | null>;
323
+ /**
324
+ * Wrapper around requestHandler that fetches requests from RequestList/RequestQueue
325
+ * then retries them in a case of an error, etc.
326
+ */
327
+ protected _runTaskFunction(): Promise<void>;
328
+ /**
329
+ * Run async callback with given timeout and retry.
330
+ * @ignore
331
+ */
332
+ protected _timeoutAndRetry(handler: () => Promise<unknown>, timeout: number, error: Error | string, maxRetries?: number, retried?: number): Promise<void>;
333
+ /**
334
+ * Returns true if either RequestList or RequestQueue have a request ready for processing.
335
+ */
336
+ protected _isTaskReadyFunction(): Promise<boolean>;
337
+ /**
338
+ * Returns true if both RequestList and RequestQueue have all requests finished.
339
+ */
340
+ protected _defaultIsFinishedFunction(): Promise<boolean>;
341
+ /**
342
+ * Handles errors thrown by user provided handleRequestFunction()
343
+ */
344
+ protected _requestFunctionErrorHandler(error: Error, crawlingContext: Context, source: RequestList | RequestQueue): Promise<void>;
345
+ protected _handleFailedRequestHandler(crawlingContext: ErrorContext): Promise<void>;
346
+ /**
347
+ * Updates handledRequestsCount from possibly stored counts,
348
+ * usually after worker migration. Since one of the stores
349
+ * needs to have priority when both are present,
350
+ * it is the request queue, because generally, the request
351
+ * list will first be dumped into the queue and then left
352
+ * empty.
353
+ */
354
+ protected _loadHandledRequestCount(): Promise<void>;
355
+ protected _executeHooks<HookLike extends (...args: any[]) => Awaitable<void>>(hooks: HookLike[], ...args: Parameters<HookLike>): Promise<void>;
356
+ /**
357
+ * Function for cleaning up after all request are processed.
358
+ * @ignore
359
+ */
360
+ teardown(): Promise<void>;
361
+ protected _handlePropertyNameChange<New, Old>({ newProperty, newName, oldProperty, oldName, propertyKey, allowUndefined, }: HandlePropertyNameChangeData<New, Old>): void;
362
+ }
363
+ /** @internal */
364
+ export declare function basicCrawlerEnqueueLinks(options: BasicCrawlerEnqueueLinksOptions, requestQueue?: RequestQueue): Promise<import("packages/core/dist/storages/storage").BatchAddRequestsResult>;
365
+ export interface CreateContextOptions {
366
+ request: Request;
367
+ session?: Session;
368
+ proxyInfo?: ProxyInfo;
369
+ }
370
+ interface HandlePropertyNameChangeData<New, Old> {
371
+ oldProperty?: Old;
372
+ newProperty?: New;
373
+ oldName: string;
374
+ newName: string;
375
+ propertyKey: string;
376
+ allowUndefined?: boolean;
377
+ }
378
+ export {};
379
+ //# sourceMappingURL=basic-crawler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"basic-crawler.d.ts","sourceRoot":"","sources":["../../src/internals/basic-crawler.ts"],"names":[],"mappings":"AAAA,OAAmB,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAG7C,OAAO,EACH,cAAc,EACd,qBAAqB,EACrB,mBAAmB,EACnB,+BAA+B,EAE/B,SAAS,EACT,kBAAkB,EAClB,OAAO,EACP,WAAW,EACX,YAAY,EACZ,OAAO,EACP,WAAW,EACX,kBAAkB,EAClB,UAAU,EAEV,KAAK,eAAe,EACpB,cAAc,EACd,4BAA4B,EAE5B,aAAa,EACb,YAAY,EAEZ,eAAe,EAClB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG3C,MAAM,WAAW,2BAA4B,SAAQ,eAAe;IAChE,OAAO,EAAE,YAAY,CAAC;IACtB,YAAY,EAAE,C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