@crawlee/core 4.0.0-beta.1 → 4.0.0-beta.100
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.
- package/README.md +17 -13
- package/autoscaling/autoscaled_pool.d.ts +69 -156
- package/autoscaling/autoscaled_pool.js +97 -252
- package/autoscaling/client_load_signal.d.ts +59 -0
- package/autoscaling/client_load_signal.js +73 -0
- package/autoscaling/concurrency_system.d.ts +283 -0
- package/autoscaling/concurrency_system.js +350 -0
- package/autoscaling/cpu_load_signal.d.ts +44 -0
- package/autoscaling/cpu_load_signal.js +46 -0
- package/autoscaling/event_loop_load_signal.d.ts +54 -0
- package/autoscaling/event_loop_load_signal.js +60 -0
- package/autoscaling/index.d.ts +6 -1
- package/autoscaling/index.js +6 -1
- package/autoscaling/load_signal.d.ts +99 -0
- package/autoscaling/load_signal.js +103 -0
- package/autoscaling/memory_load_signal.d.ts +56 -0
- package/autoscaling/memory_load_signal.js +106 -0
- package/autoscaling/snapshotter.d.ts +61 -163
- package/autoscaling/snapshotter.js +45 -270
- package/autoscaling/system_status.d.ts +63 -83
- package/autoscaling/system_status.js +90 -120
- package/autoscaling/weighted_avg.d.ts +5 -0
- package/autoscaling/weighted_avg.js +14 -0
- package/byte_utils.d.ts +17 -0
- package/byte_utils.js +42 -0
- package/configuration.d.ts +96 -230
- package/configuration.js +170 -226
- package/cookie_utils.d.ts +4 -3
- package/cookie_utils.js +22 -13
- package/crawlers/context_pipeline.d.ts +70 -0
- package/crawlers/context_pipeline.js +122 -0
- package/crawlers/crawler_commons.d.ts +96 -40
- package/crawlers/crawler_commons.js +15 -24
- package/crawlers/error_snapshotter.d.ts +3 -3
- package/crawlers/error_snapshotter.js +2 -3
- package/crawlers/error_tracker.d.ts +2 -2
- package/crawlers/error_tracker.js +0 -1
- package/crawlers/index.d.ts +1 -3
- package/crawlers/index.js +1 -3
- package/crawlers/internals/types.d.ts +7 -0
- package/crawlers/internals/types.js +1 -0
- package/crawlers/statistics.d.ts +28 -23
- package/crawlers/statistics.js +38 -34
- package/debug.d.ts +36 -0
- package/debug.js +70 -0
- package/enqueue_links/enqueue_links.d.ts +59 -68
- package/enqueue_links/enqueue_links.js +57 -62
- package/enqueue_links/index.d.ts +0 -1
- package/enqueue_links/index.js +0 -1
- package/enqueue_links/shared.d.ts +39 -26
- package/enqueue_links/shared.js +89 -67
- package/errors.d.ts +53 -4
- package/errors.js +70 -5
- package/events/event_manager.d.ts +34 -8
- package/events/event_manager.js +8 -10
- package/events/index.d.ts +0 -1
- package/events/index.js +0 -1
- package/events/local_event_manager.d.ts +15 -5
- package/events/local_event_manager.js +37 -40
- package/index.d.ts +6 -4
- package/index.js +5 -3
- package/iterables.d.ts +79 -0
- package/iterables.js +134 -0
- package/log.d.ts +82 -3
- package/log.js +102 -1
- package/memory-storage/consts.d.ts +4 -0
- package/memory-storage/consts.js +4 -0
- package/memory-storage/index.d.ts +1 -0
- package/memory-storage/index.js +1 -0
- package/memory-storage/memory-storage.d.ts +46 -0
- package/memory-storage/memory-storage.js +136 -0
- package/memory-storage/resource-clients/common/base-client.d.ts +4 -0
- package/memory-storage/resource-clients/common/base-client.js +6 -0
- package/memory-storage/resource-clients/dataset.d.ts +40 -0
- package/memory-storage/resource-clients/dataset.js +113 -0
- package/memory-storage/resource-clients/key-value-store.d.ts +63 -0
- package/memory-storage/resource-clients/key-value-store.js +203 -0
- package/memory-storage/resource-clients/request-queue.d.ts +96 -0
- package/memory-storage/resource-clients/request-queue.js +421 -0
- package/memory-storage/utils.d.ts +16 -0
- package/memory-storage/utils.js +41 -0
- package/owned_or_injected.d.ts +60 -0
- package/owned_or_injected.js +98 -0
- package/package.json +13 -12
- package/proxy_configuration.d.ts +29 -152
- package/proxy_configuration.js +21 -173
- package/recoverable_state.d.ts +120 -0
- package/recoverable_state.js +143 -0
- package/request.d.ts +85 -17
- package/request.js +107 -36
- package/router.d.ts +194 -19
- package/router.js +177 -32
- package/serialization.d.ts +0 -1
- package/serialization.js +1 -2
- package/service_locator.d.ts +156 -0
- package/service_locator.js +244 -0
- package/session_pool/consts.d.ts +1 -2
- package/session_pool/consts.js +1 -2
- package/session_pool/errors.d.ts +0 -1
- package/session_pool/errors.js +0 -1
- package/session_pool/fingerprint.d.ts +9 -0
- package/session_pool/fingerprint.js +30 -0
- package/session_pool/index.d.ts +0 -2
- package/session_pool/index.js +0 -2
- package/session_pool/session.d.ts +37 -75
- package/session_pool/session.js +49 -102
- package/session_pool/session_pool.d.ts +85 -90
- package/session_pool/session_pool.js +131 -120
- package/storages/access_checking.d.ts +1 -2
- package/storages/access_checking.js +5 -2
- package/storages/dataset.d.ts +103 -54
- package/storages/dataset.js +174 -132
- package/storages/index.d.ts +8 -7
- package/storages/index.js +6 -7
- package/storages/key_value_store.d.ts +167 -39
- package/storages/key_value_store.js +274 -127
- package/storages/key_value_store_codec.d.ts +32 -0
- package/storages/key_value_store_codec.js +113 -0
- package/storages/request_dedup_cache.d.ts +23 -0
- package/storages/request_dedup_cache.js +48 -0
- package/storages/request_list.d.ts +54 -98
- package/storages/request_list.js +99 -75
- package/storages/request_loader.d.ts +96 -0
- package/storages/request_loader.js +1 -0
- package/storages/request_manager.d.ts +33 -0
- package/storages/request_manager.js +1 -0
- package/storages/request_manager_tandem.d.ts +106 -0
- package/storages/request_manager_tandem.js +197 -0
- package/storages/request_queue.d.ts +287 -47
- package/storages/request_queue.js +620 -215
- package/storages/{sitemap_request_list.d.ts → sitemap_request_loader.d.ts} +38 -46
- package/storages/{sitemap_request_list.js → sitemap_request_loader.js} +58 -65
- package/storages/storage_instance_manager.d.ts +88 -0
- package/storages/storage_instance_manager.js +256 -0
- package/storages/storage_stats.d.ts +48 -0
- package/storages/storage_stats.js +29 -0
- package/storages/utils.d.ts +54 -9
- package/storages/utils.js +64 -13
- package/system-info/cpu-info.d.ts +67 -0
- package/system-info/cpu-info.js +216 -0
- package/system-info/memory-info.d.ts +31 -0
- package/system-info/memory-info.js +115 -0
- package/system-info/ps-tree.d.ts +17 -0
- package/system-info/ps-tree.js +144 -0
- package/system-info/runtime.d.ts +14 -0
- package/system-info/runtime.js +80 -0
- package/typedefs.d.ts +0 -6
- package/typedefs.js +0 -1
- package/validators.d.ts +8 -1
- package/validators.js +10 -3
- package/autoscaling/autoscaled_pool.d.ts.map +0 -1
- package/autoscaling/autoscaled_pool.js.map +0 -1
- package/autoscaling/index.d.ts.map +0 -1
- package/autoscaling/index.js.map +0 -1
- package/autoscaling/snapshotter.d.ts.map +0 -1
- package/autoscaling/snapshotter.js.map +0 -1
- package/autoscaling/system_status.d.ts.map +0 -1
- package/autoscaling/system_status.js.map +0 -1
- package/configuration.d.ts.map +0 -1
- package/configuration.js.map +0 -1
- package/cookie_utils.d.ts.map +0 -1
- package/cookie_utils.js.map +0 -1
- package/crawlers/crawler_commons.d.ts.map +0 -1
- package/crawlers/crawler_commons.js.map +0 -1
- package/crawlers/crawler_extension.d.ts +0 -12
- package/crawlers/crawler_extension.d.ts.map +0 -1
- package/crawlers/crawler_extension.js +0 -14
- package/crawlers/crawler_extension.js.map +0 -1
- package/crawlers/crawler_utils.d.ts +0 -10
- package/crawlers/crawler_utils.d.ts.map +0 -1
- package/crawlers/crawler_utils.js +0 -12
- package/crawlers/crawler_utils.js.map +0 -1
- package/crawlers/error_snapshotter.d.ts.map +0 -1
- package/crawlers/error_snapshotter.js.map +0 -1
- package/crawlers/error_tracker.d.ts.map +0 -1
- package/crawlers/error_tracker.js.map +0 -1
- package/crawlers/index.d.ts.map +0 -1
- package/crawlers/index.js.map +0 -1
- package/crawlers/statistics.d.ts.map +0 -1
- package/crawlers/statistics.js.map +0 -1
- package/enqueue_links/enqueue_links.d.ts.map +0 -1
- package/enqueue_links/enqueue_links.js.map +0 -1
- package/enqueue_links/index.d.ts.map +0 -1
- package/enqueue_links/index.js.map +0 -1
- package/enqueue_links/shared.d.ts.map +0 -1
- package/enqueue_links/shared.js.map +0 -1
- package/errors.d.ts.map +0 -1
- package/errors.js.map +0 -1
- package/events/event_manager.d.ts.map +0 -1
- package/events/event_manager.js.map +0 -1
- package/events/index.d.ts.map +0 -1
- package/events/index.js.map +0 -1
- package/events/local_event_manager.d.ts.map +0 -1
- package/events/local_event_manager.js.map +0 -1
- package/http_clients/base-http-client.d.ts +0 -134
- package/http_clients/base-http-client.d.ts.map +0 -1
- package/http_clients/base-http-client.js +0 -33
- package/http_clients/base-http-client.js.map +0 -1
- package/http_clients/form-data-like.d.ts +0 -67
- package/http_clients/form-data-like.d.ts.map +0 -1
- package/http_clients/form-data-like.js +0 -5
- package/http_clients/form-data-like.js.map +0 -1
- package/http_clients/got-scraping-http-client.d.ts +0 -15
- package/http_clients/got-scraping-http-client.d.ts.map +0 -1
- package/http_clients/got-scraping-http-client.js +0 -69
- package/http_clients/got-scraping-http-client.js.map +0 -1
- package/http_clients/index.d.ts +0 -3
- package/http_clients/index.d.ts.map +0 -1
- package/http_clients/index.js +0 -3
- package/http_clients/index.js.map +0 -1
- package/index.d.ts.map +0 -1
- package/index.js.map +0 -1
- package/log.d.ts.map +0 -1
- package/log.js.map +0 -1
- package/proxy_configuration.d.ts.map +0 -1
- package/proxy_configuration.js.map +0 -1
- package/request.d.ts.map +0 -1
- package/request.js.map +0 -1
- package/router.d.ts.map +0 -1
- package/router.js.map +0 -1
- package/serialization.d.ts.map +0 -1
- package/serialization.js.map +0 -1
- package/session_pool/consts.d.ts.map +0 -1
- package/session_pool/consts.js.map +0 -1
- package/session_pool/errors.d.ts.map +0 -1
- package/session_pool/errors.js.map +0 -1
- package/session_pool/events.d.ts +0 -3
- package/session_pool/events.d.ts.map +0 -1
- package/session_pool/events.js +0 -3
- package/session_pool/events.js.map +0 -1
- package/session_pool/index.d.ts.map +0 -1
- package/session_pool/index.js.map +0 -1
- package/session_pool/session.d.ts.map +0 -1
- package/session_pool/session.js.map +0 -1
- package/session_pool/session_pool.d.ts.map +0 -1
- package/session_pool/session_pool.js.map +0 -1
- package/storages/access_checking.d.ts.map +0 -1
- package/storages/access_checking.js.map +0 -1
- package/storages/dataset.d.ts.map +0 -1
- package/storages/dataset.js.map +0 -1
- package/storages/index.d.ts.map +0 -1
- package/storages/index.js.map +0 -1
- package/storages/key_value_store.d.ts.map +0 -1
- package/storages/key_value_store.js.map +0 -1
- package/storages/request_list.d.ts.map +0 -1
- package/storages/request_list.js.map +0 -1
- package/storages/request_provider.d.ts +0 -307
- package/storages/request_provider.d.ts.map +0 -1
- package/storages/request_provider.js +0 -555
- package/storages/request_provider.js.map +0 -1
- package/storages/request_queue.d.ts.map +0 -1
- package/storages/request_queue.js.map +0 -1
- package/storages/request_queue_v2.d.ts +0 -87
- package/storages/request_queue_v2.d.ts.map +0 -1
- package/storages/request_queue_v2.js +0 -438
- package/storages/request_queue_v2.js.map +0 -1
- package/storages/sitemap_request_list.d.ts.map +0 -1
- package/storages/sitemap_request_list.js.map +0 -1
- package/storages/storage_manager.d.ts +0 -58
- package/storages/storage_manager.d.ts.map +0 -1
- package/storages/storage_manager.js +0 -105
- package/storages/storage_manager.js.map +0 -1
- package/storages/utils.d.ts.map +0 -1
- package/storages/utils.js.map +0 -1
- package/tsconfig.build.tsbuildinfo +0 -1
- package/typedefs.d.ts.map +0 -1
- package/typedefs.js.map +0 -1
- package/validators.d.ts.map +0 -1
- package/validators.js.map +0 -1
package/crawlers/statistics.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { Configuration } from '../configuration.js';
|
|
1
|
+
import type { CrawleeLogger } from '../log.js';
|
|
3
2
|
import { KeyValueStore } from '../storages/key_value_store.js';
|
|
4
3
|
import { ErrorTracker } from './error_tracker.js';
|
|
5
4
|
/**
|
|
@@ -17,7 +16,7 @@ export interface PersistenceOptions {
|
|
|
17
16
|
* statistics for requests.
|
|
18
17
|
*
|
|
19
18
|
* All statistic information is saved on key value store
|
|
20
|
-
* under the key `
|
|
19
|
+
* under the key `CRAWLEE_CRAWLER_STATISTICS_*`, persists between
|
|
21
20
|
* migrations and abort/resurrect
|
|
22
21
|
*
|
|
23
22
|
* @category Crawlers
|
|
@@ -27,15 +26,15 @@ export declare class Statistics {
|
|
|
27
26
|
/**
|
|
28
27
|
* An error tracker for final retry errors.
|
|
29
28
|
*/
|
|
30
|
-
errorTracker: ErrorTracker;
|
|
29
|
+
readonly errorTracker: ErrorTracker;
|
|
31
30
|
/**
|
|
32
31
|
* An error tracker for retry errors prior to the final retry.
|
|
33
32
|
*/
|
|
34
|
-
errorTrackerRetry: ErrorTracker;
|
|
33
|
+
readonly errorTrackerRetry: ErrorTracker;
|
|
35
34
|
/**
|
|
36
35
|
* Statistic instance id.
|
|
37
36
|
*/
|
|
38
|
-
readonly id:
|
|
37
|
+
readonly id: string;
|
|
39
38
|
/**
|
|
40
39
|
* Current statistic state used for doing calculations on {@link Statistics.calculate} calls
|
|
41
40
|
*/
|
|
@@ -44,12 +43,8 @@ export declare class Statistics {
|
|
|
44
43
|
* Contains the current retries histogram. Index 0 means 0 retries, index 2, 2 retries, and so on
|
|
45
44
|
*/
|
|
46
45
|
readonly requestRetryHistogram: number[];
|
|
47
|
-
/**
|
|
48
|
-
* Contains the associated Configuration instance
|
|
49
|
-
*/
|
|
50
|
-
private readonly config;
|
|
51
46
|
protected keyValueStore?: KeyValueStore;
|
|
52
|
-
protected persistStateKey: string;
|
|
47
|
+
protected readonly persistStateKey: string;
|
|
53
48
|
private logIntervalMillis;
|
|
54
49
|
private logMessage;
|
|
55
50
|
private listener;
|
|
@@ -57,8 +52,9 @@ export declare class Statistics {
|
|
|
57
52
|
private readonly log;
|
|
58
53
|
private instanceStart;
|
|
59
54
|
private logInterval;
|
|
60
|
-
private
|
|
55
|
+
private _events?;
|
|
61
56
|
private persistenceOptions;
|
|
57
|
+
private get events();
|
|
62
58
|
/**
|
|
63
59
|
* @internal
|
|
64
60
|
*/
|
|
@@ -90,6 +86,12 @@ export declare class Statistics {
|
|
|
90
86
|
* @ignore
|
|
91
87
|
*/
|
|
92
88
|
failJob(id: number | string, retryCount: number): void;
|
|
89
|
+
/**
|
|
90
|
+
* Discards a started job without affecting the finished/failed counters, e.g. when a request
|
|
91
|
+
* turns out to be skipped (robots.txt, enqueue strategy) after `startJob` was already called for it.
|
|
92
|
+
* @ignore
|
|
93
|
+
*/
|
|
94
|
+
discardJob(id: number | string): void;
|
|
93
95
|
/**
|
|
94
96
|
* Calculate the current statistics
|
|
95
97
|
*/
|
|
@@ -111,7 +113,7 @@ export declare class Statistics {
|
|
|
111
113
|
* Stops logging and remove event listeners, then persist
|
|
112
114
|
*/
|
|
113
115
|
stopCapturing(): Promise<void>;
|
|
114
|
-
|
|
116
|
+
private saveRetryCountForJob;
|
|
115
117
|
/**
|
|
116
118
|
* Persist internal state to the key value store
|
|
117
119
|
* @param options - Override the persistence options provided in the constructor
|
|
@@ -120,8 +122,8 @@ export declare class Statistics {
|
|
|
120
122
|
/**
|
|
121
123
|
* Loads the current statistic from the key value store if any
|
|
122
124
|
*/
|
|
123
|
-
protected
|
|
124
|
-
|
|
125
|
+
protected maybeLoadStatistics(): Promise<void>;
|
|
126
|
+
private teardown;
|
|
125
127
|
/**
|
|
126
128
|
* Make this class serializable when called with `JSON.stringify(statsInstance)` directly
|
|
127
129
|
* or through `keyValueStore.setValue('KEY', statsInstance)`
|
|
@@ -146,17 +148,12 @@ export interface StatisticsOptions {
|
|
|
146
148
|
* Parent logger instance, the statistics will create a child logger from this.
|
|
147
149
|
* @default crawler.log
|
|
148
150
|
*/
|
|
149
|
-
log?:
|
|
151
|
+
log?: CrawleeLogger;
|
|
150
152
|
/**
|
|
151
153
|
* Key value store instance to persist the statistics.
|
|
152
154
|
* If not provided, the default one will be used when capturing starts
|
|
153
155
|
*/
|
|
154
156
|
keyValueStore?: KeyValueStore;
|
|
155
|
-
/**
|
|
156
|
-
* Configuration instance to use
|
|
157
|
-
* @default Configuration.getGlobalConfig()
|
|
158
|
-
*/
|
|
159
|
-
config?: Configuration;
|
|
160
157
|
/**
|
|
161
158
|
* Control how and when to persist the statistics.
|
|
162
159
|
*/
|
|
@@ -166,13 +163,22 @@ export interface StatisticsOptions {
|
|
|
166
163
|
* @default false
|
|
167
164
|
*/
|
|
168
165
|
saveErrorSnapshots?: boolean;
|
|
166
|
+
/**
|
|
167
|
+
* A unique identifier for this statistics instance. This ID is used for persistence
|
|
168
|
+
* to the key value store, ensuring the same statistics can be loaded after script restarts.
|
|
169
|
+
*
|
|
170
|
+
* If not provided, an auto-incremented ID will be used for backward compatibility.
|
|
171
|
+
* This means statistics may not persist correctly across script restarts
|
|
172
|
+
* if crawler creation order changes.
|
|
173
|
+
*/
|
|
174
|
+
id?: string;
|
|
169
175
|
}
|
|
170
176
|
/**
|
|
171
177
|
* Format of the persisted stats
|
|
172
178
|
*/
|
|
173
179
|
export interface StatisticPersistedState extends Omit<StatisticState, 'statsPersistedAt'> {
|
|
174
180
|
requestRetryHistogram: number[];
|
|
175
|
-
statsId:
|
|
181
|
+
statsId: string;
|
|
176
182
|
requestAvgFailedDurationMillis: number;
|
|
177
183
|
requestAvgFinishedDurationMillis: number;
|
|
178
184
|
requestTotalDurationMillis: number;
|
|
@@ -201,4 +207,3 @@ export interface StatisticState {
|
|
|
201
207
|
retryErrors: Record<string, unknown>;
|
|
202
208
|
requestsWithStatusCode: Record<string, number>;
|
|
203
209
|
}
|
|
204
|
-
//# sourceMappingURL=statistics.d.ts.map
|
package/crawlers/statistics.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import ow from 'ow';
|
|
2
|
-
import {
|
|
3
|
-
import { log as defaultLog } from '../log.js';
|
|
2
|
+
import { serviceLocator } from '../service_locator.js';
|
|
4
3
|
import { KeyValueStore } from '../storages/key_value_store.js';
|
|
5
4
|
import { ErrorTracker } from './error_tracker.js';
|
|
6
5
|
/**
|
|
@@ -30,7 +29,7 @@ const errorTrackerConfig = {
|
|
|
30
29
|
* statistics for requests.
|
|
31
30
|
*
|
|
32
31
|
* All statistic information is saved on key value store
|
|
33
|
-
* under the key `
|
|
32
|
+
* under the key `CRAWLEE_CRAWLER_STATISTICS_*`, persists between
|
|
34
33
|
* migrations and abort/resurrect
|
|
35
34
|
*
|
|
36
35
|
* @category Crawlers
|
|
@@ -48,7 +47,7 @@ export class Statistics {
|
|
|
48
47
|
/**
|
|
49
48
|
* Statistic instance id.
|
|
50
49
|
*/
|
|
51
|
-
id
|
|
50
|
+
id;
|
|
52
51
|
/**
|
|
53
52
|
* Current statistic state used for doing calculations on {@link Statistics.calculate} calls
|
|
54
53
|
*/
|
|
@@ -57,12 +56,8 @@ export class Statistics {
|
|
|
57
56
|
* Contains the current retries histogram. Index 0 means 0 retries, index 2, 2 retries, and so on
|
|
58
57
|
*/
|
|
59
58
|
requestRetryHistogram = [];
|
|
60
|
-
/**
|
|
61
|
-
* Contains the associated Configuration instance
|
|
62
|
-
*/
|
|
63
|
-
config;
|
|
64
59
|
keyValueStore = undefined;
|
|
65
|
-
persistStateKey
|
|
60
|
+
persistStateKey;
|
|
66
61
|
logIntervalMillis;
|
|
67
62
|
logMessage;
|
|
68
63
|
listener;
|
|
@@ -70,8 +65,14 @@ export class Statistics {
|
|
|
70
65
|
log;
|
|
71
66
|
instanceStart;
|
|
72
67
|
logInterval;
|
|
73
|
-
|
|
68
|
+
_events;
|
|
74
69
|
persistenceOptions;
|
|
70
|
+
get events() {
|
|
71
|
+
if (!this._events) {
|
|
72
|
+
this._events = serviceLocator.getEventManager();
|
|
73
|
+
}
|
|
74
|
+
return this._events;
|
|
75
|
+
}
|
|
75
76
|
/**
|
|
76
77
|
* @internal
|
|
77
78
|
*/
|
|
@@ -81,22 +82,22 @@ export class Statistics {
|
|
|
81
82
|
logMessage: ow.optional.string,
|
|
82
83
|
log: ow.optional.object,
|
|
83
84
|
keyValueStore: ow.optional.object,
|
|
84
|
-
config: ow.optional.object,
|
|
85
85
|
persistenceOptions: ow.optional.object,
|
|
86
86
|
saveErrorSnapshots: ow.optional.boolean,
|
|
87
|
+
id: ow.optional.any(ow.number, ow.string),
|
|
87
88
|
}));
|
|
88
|
-
const { logIntervalSecs = 60, logMessage = 'Statistics', keyValueStore,
|
|
89
|
+
const { logIntervalSecs = 60, logMessage = 'Statistics', keyValueStore, persistenceOptions = {
|
|
89
90
|
enable: true,
|
|
90
|
-
}, saveErrorSnapshots = false, } = options;
|
|
91
|
-
this.
|
|
91
|
+
}, saveErrorSnapshots = false, id, } = options;
|
|
92
|
+
this.id = id ?? String(Statistics.id++);
|
|
93
|
+
this.persistStateKey = `CRAWLEE_CRAWLER_STATISTICS_${this.id}`;
|
|
94
|
+
this.log = (options.log ?? serviceLocator.getLogger()).child({ prefix: 'Statistics' });
|
|
92
95
|
this.errorTracker = new ErrorTracker({ ...errorTrackerConfig, saveErrorSnapshots });
|
|
93
96
|
this.errorTrackerRetry = new ErrorTracker({ ...errorTrackerConfig, saveErrorSnapshots });
|
|
94
97
|
this.logIntervalMillis = logIntervalSecs * 1000;
|
|
95
98
|
this.logMessage = logMessage;
|
|
96
99
|
this.keyValueStore = keyValueStore;
|
|
97
100
|
this.listener = this.persistState.bind(this);
|
|
98
|
-
this.events = config.getEventManager();
|
|
99
|
-
this.config = config;
|
|
100
101
|
this.persistenceOptions = persistenceOptions;
|
|
101
102
|
// initialize by "resetting"
|
|
102
103
|
this.reset();
|
|
@@ -128,7 +129,7 @@ export class Statistics {
|
|
|
128
129
|
this.requestRetryHistogram.length = 0;
|
|
129
130
|
this.requestsInProgress.clear();
|
|
130
131
|
this.instanceStart = Date.now();
|
|
131
|
-
this.
|
|
132
|
+
this.teardown();
|
|
132
133
|
}
|
|
133
134
|
/**
|
|
134
135
|
* @param options - Override the persistence options provided in the constructor
|
|
@@ -174,7 +175,7 @@ export class Statistics {
|
|
|
174
175
|
const jobDurationMillis = job.finish();
|
|
175
176
|
this.state.requestsFinished++;
|
|
176
177
|
this.state.requestTotalFinishedDurationMillis += jobDurationMillis;
|
|
177
|
-
this.
|
|
178
|
+
this.saveRetryCountForJob(retryCount);
|
|
178
179
|
if (jobDurationMillis < this.state.requestMinDurationMillis)
|
|
179
180
|
this.state.requestMinDurationMillis = jobDurationMillis;
|
|
180
181
|
if (jobDurationMillis > this.state.requestMaxDurationMillis)
|
|
@@ -191,7 +192,15 @@ export class Statistics {
|
|
|
191
192
|
return;
|
|
192
193
|
this.state.requestTotalFailedDurationMillis += job.finish();
|
|
193
194
|
this.state.requestsFailed++;
|
|
194
|
-
this.
|
|
195
|
+
this.saveRetryCountForJob(retryCount);
|
|
196
|
+
this.requestsInProgress.delete(id);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Discards a started job without affecting the finished/failed counters, e.g. when a request
|
|
200
|
+
* turns out to be skipped (robots.txt, enqueue strategy) after `startJob` was already called for it.
|
|
201
|
+
* @ignore
|
|
202
|
+
*/
|
|
203
|
+
discardJob(id) {
|
|
195
204
|
this.requestsInProgress.delete(id);
|
|
196
205
|
}
|
|
197
206
|
/**
|
|
@@ -216,12 +225,12 @@ export class Statistics {
|
|
|
216
225
|
* displaying the current state in predefined intervals
|
|
217
226
|
*/
|
|
218
227
|
async startCapturing() {
|
|
219
|
-
this.keyValueStore ??= await KeyValueStore.open(null, {
|
|
228
|
+
this.keyValueStore ??= await KeyValueStore.open(null, { configuration: serviceLocator.getConfiguration() });
|
|
220
229
|
if (this.state.crawlerStartedAt === null) {
|
|
221
230
|
this.state.crawlerStartedAt = new Date();
|
|
222
231
|
}
|
|
223
232
|
if (this.persistenceOptions.enable) {
|
|
224
|
-
await this.
|
|
233
|
+
await this.maybeLoadStatistics();
|
|
225
234
|
this.events.on("persistState" /* EventType.PERSIST_STATE */, this.listener);
|
|
226
235
|
}
|
|
227
236
|
this.logInterval = setInterval(() => {
|
|
@@ -235,11 +244,11 @@ export class Statistics {
|
|
|
235
244
|
* Stops logging and remove event listeners, then persist
|
|
236
245
|
*/
|
|
237
246
|
async stopCapturing() {
|
|
238
|
-
this.
|
|
247
|
+
this.teardown();
|
|
239
248
|
this.state.crawlerFinishedAt = new Date();
|
|
240
249
|
await this.persistState();
|
|
241
250
|
}
|
|
242
|
-
|
|
251
|
+
saveRetryCountForJob(retryCount) {
|
|
243
252
|
if (retryCount > 0)
|
|
244
253
|
this.state.requestsRetries++;
|
|
245
254
|
this.requestRetryHistogram[retryCount] ??= 0;
|
|
@@ -258,20 +267,14 @@ export class Statistics {
|
|
|
258
267
|
return;
|
|
259
268
|
}
|
|
260
269
|
this.log.debug('Persisting state', { persistStateKey: this.persistStateKey });
|
|
261
|
-
// use half the interval of `persistState` to avoid race conditions
|
|
262
|
-
const persistStateIntervalMillis = this.config.get('persistStateIntervalMillis');
|
|
263
|
-
const timeoutSecs = persistStateIntervalMillis / 2_000;
|
|
264
270
|
await this.keyValueStore
|
|
265
|
-
.setValue(this.persistStateKey, this.toJSON()
|
|
266
|
-
timeoutSecs,
|
|
267
|
-
doNotRetryTimeouts: true,
|
|
268
|
-
})
|
|
271
|
+
.setValue(this.persistStateKey, this.toJSON())
|
|
269
272
|
.catch((error) => this.log.warning(`Failed to persist the statistics to ${this.persistStateKey}`, { error }));
|
|
270
273
|
}
|
|
271
274
|
/**
|
|
272
275
|
* Loads the current statistic from the key value store if any
|
|
273
276
|
*/
|
|
274
|
-
async
|
|
277
|
+
async maybeLoadStatistics() {
|
|
275
278
|
// this might be called before startCapturing was called without using await, should not crash
|
|
276
279
|
if (!this.keyValueStore) {
|
|
277
280
|
return;
|
|
@@ -306,9 +309,11 @@ export class Statistics {
|
|
|
306
309
|
this.instanceStart = Date.now() - (+this.state.statsPersistedAt - savedState.crawlerLastStartTimestamp);
|
|
307
310
|
this.log.debug('Loaded from KeyValueStore');
|
|
308
311
|
}
|
|
309
|
-
|
|
312
|
+
teardown() {
|
|
310
313
|
// this can be called before a call to startCapturing happens (or in a 'finally' block)
|
|
311
|
-
|
|
314
|
+
// Only unsubscribe if event manager was already resolved — avoid eagerly resolving it
|
|
315
|
+
// (e.g. during the constructor's reset() call, which would capture the wrong context)
|
|
316
|
+
this._events?.off("persistState" /* EventType.PERSIST_STATE */, this.listener);
|
|
312
317
|
if (this.logInterval) {
|
|
313
318
|
clearInterval(this.logInterval);
|
|
314
319
|
this.logInterval = null;
|
|
@@ -343,4 +348,3 @@ export class Statistics {
|
|
|
343
348
|
return result;
|
|
344
349
|
}
|
|
345
350
|
}
|
|
346
|
-
//# sourceMappingURL=statistics.js.map
|
package/debug.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { IncomingMessage } from 'node:http';
|
|
2
|
+
import type { Dictionary } from '@crawlee/types';
|
|
3
|
+
import type { Request } from './request.js';
|
|
4
|
+
interface BrowserResponseLike {
|
|
5
|
+
status(): number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Creates a standardized debug info from request and response. This info is usually added to dataset under the hidden `#debug` field.
|
|
9
|
+
*
|
|
10
|
+
* @param request [Request](https://sdk.apify.com/docs/api/request) object.
|
|
11
|
+
* @param [response]
|
|
12
|
+
* Puppeteer [`Response`](https://pptr.dev/#?product=Puppeteer&version=v1.11.0&show=api-class-response)
|
|
13
|
+
* or NodeJS [`http.IncomingMessage`](https://nodejs.org/api/http.html#http_class_http_serverresponse).
|
|
14
|
+
* @param [additionalFields] Object containing additional fields to be added.
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export declare function createRequestDebugInfo(request: Request, response?: IncomingMessage | Partial<BrowserResponseLike>, additionalFields?: Dictionary): Dictionary;
|
|
19
|
+
/**
|
|
20
|
+
* Returns a human-readable label for an unknown value,
|
|
21
|
+
* suitable for embedding in error messages and log output.
|
|
22
|
+
*
|
|
23
|
+
* Returns `constructor.name` when available (e.g. `"Configuration"`, `"Number"`),
|
|
24
|
+
* otherwise falls back to `util.inspect` (e.g. for `null`, `undefined`).
|
|
25
|
+
*
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
export declare function inspectValue(value: unknown): string;
|
|
29
|
+
/**
|
|
30
|
+
* Returns the type of a value as a lowercase string, with `Date`, `Buffer` and `RegExp` reported
|
|
31
|
+
* by their constructor name. Used for building validation error messages.
|
|
32
|
+
*
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
export declare function getObjectType(value: unknown): string;
|
|
36
|
+
export {};
|
package/debug.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { inspect } from 'node:util';
|
|
2
|
+
import ow from 'ow';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a standardized debug info from request and response. This info is usually added to dataset under the hidden `#debug` field.
|
|
5
|
+
*
|
|
6
|
+
* @param request [Request](https://sdk.apify.com/docs/api/request) object.
|
|
7
|
+
* @param [response]
|
|
8
|
+
* Puppeteer [`Response`](https://pptr.dev/#?product=Puppeteer&version=v1.11.0&show=api-class-response)
|
|
9
|
+
* or NodeJS [`http.IncomingMessage`](https://nodejs.org/api/http.html#http_class_http_serverresponse).
|
|
10
|
+
* @param [additionalFields] Object containing additional fields to be added.
|
|
11
|
+
*
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
export function createRequestDebugInfo(request, response = {}, additionalFields = {}) {
|
|
15
|
+
ow(request, ow.object);
|
|
16
|
+
ow(response, ow.object);
|
|
17
|
+
ow(additionalFields, ow.object);
|
|
18
|
+
return {
|
|
19
|
+
requestId: request.id,
|
|
20
|
+
url: request.url,
|
|
21
|
+
loadedUrl: request.loadedUrl,
|
|
22
|
+
method: request.method,
|
|
23
|
+
retryCount: request.retryCount,
|
|
24
|
+
errorMessages: request.errorMessages,
|
|
25
|
+
// Puppeteer response has .status() function and NodeJS response, statusCode property.
|
|
26
|
+
statusCode: 'status' in response && response.status instanceof Function
|
|
27
|
+
? response.status()
|
|
28
|
+
: response.statusCode,
|
|
29
|
+
...additionalFields,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Returns a human-readable label for an unknown value,
|
|
34
|
+
* suitable for embedding in error messages and log output.
|
|
35
|
+
*
|
|
36
|
+
* Returns `constructor.name` when available (e.g. `"Configuration"`, `"Number"`),
|
|
37
|
+
* otherwise falls back to `util.inspect` (e.g. for `null`, `undefined`).
|
|
38
|
+
*
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
export function inspectValue(value) {
|
|
42
|
+
if (typeof value === 'object' && value !== null && value.constructor?.name) {
|
|
43
|
+
return value.constructor.name;
|
|
44
|
+
}
|
|
45
|
+
return inspect(value, {
|
|
46
|
+
depth: 0,
|
|
47
|
+
compact: true,
|
|
48
|
+
maxStringLength: 64,
|
|
49
|
+
breakLength: Infinity,
|
|
50
|
+
colors: false,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Returns the type of a value as a lowercase string, with `Date`, `Buffer` and `RegExp` reported
|
|
55
|
+
* by their constructor name. Used for building validation error messages.
|
|
56
|
+
*
|
|
57
|
+
* @internal
|
|
58
|
+
*/
|
|
59
|
+
export function getObjectType(value) {
|
|
60
|
+
const simple = typeof value;
|
|
61
|
+
if (['string', 'number', 'boolean', 'bigint'].includes(simple)) {
|
|
62
|
+
return simple;
|
|
63
|
+
}
|
|
64
|
+
const objectType = Object.prototype.toString.call(value);
|
|
65
|
+
const type = /\[object (\w+)]/.exec(objectType)[1];
|
|
66
|
+
if (type === 'Uint8Array') {
|
|
67
|
+
return 'Buffer';
|
|
68
|
+
}
|
|
69
|
+
return ['Date', 'Buffer', 'RegExp'].includes(type) ? type : type.toLowerCase();
|
|
70
|
+
}
|
|
@@ -1,25 +1,29 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BatchAddRequestsResult, Dictionary } from '@crawlee/types';
|
|
2
2
|
import { type RobotsTxtFile } from '@crawlee/utils';
|
|
3
3
|
import type { SetRequired } from 'type-fest';
|
|
4
|
-
import
|
|
5
|
-
import type {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
reason: 'robotsTxt';
|
|
9
|
-
}) => Awaitable<void>;
|
|
4
|
+
import { Request } from '../request.js';
|
|
5
|
+
import type { IRequestManager } from '../storages/request_manager.js';
|
|
6
|
+
import type { AddRequestsBatchedOptions, AddRequestsBatchedResult, RequestQueueOperationOptions } from '../storages/request_queue.js';
|
|
7
|
+
import type { RequestTransform, SkippedRequestCallback, UrlPatternInput } from './shared.js';
|
|
10
8
|
export interface EnqueueLinksOptions extends RequestQueueOperationOptions {
|
|
11
9
|
/** Limit the amount of actually enqueued URLs to this number. Useful for testing across the entire crawling scope. */
|
|
12
10
|
limit?: number;
|
|
13
11
|
/** An array of URLs to enqueue. */
|
|
14
12
|
urls?: readonly string[];
|
|
15
|
-
/** A request
|
|
16
|
-
|
|
13
|
+
/** A request manager to which the URLs will be enqueued. */
|
|
14
|
+
requestManager?: IRequestManager;
|
|
17
15
|
/** A CSS selector matching links to be enqueued. */
|
|
18
16
|
selector?: string;
|
|
19
17
|
/** Sets {@link Request.userData} for newly enqueued requests. */
|
|
20
18
|
userData?: Dictionary;
|
|
21
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Sets {@link Request.label} for newly enqueued requests.
|
|
21
|
+
*
|
|
22
|
+
* Can be overwritten by `transformRequestFunction`.
|
|
23
|
+
*/
|
|
22
24
|
label?: string;
|
|
25
|
+
/** Sets {@link Request.sessionId} for newly enqueued requests. */
|
|
26
|
+
sessionId?: string;
|
|
23
27
|
/**
|
|
24
28
|
* If set to `true`, tells the crawler to skip navigation and process the request directly.
|
|
25
29
|
* @default false
|
|
@@ -31,67 +35,37 @@ export interface EnqueueLinksOptions extends RequestQueueOperationOptions {
|
|
|
31
35
|
*/
|
|
32
36
|
baseUrl?: string;
|
|
33
37
|
/**
|
|
34
|
-
* An array of
|
|
35
|
-
* containing glob pattern strings matching the URLs to be enqueued.
|
|
38
|
+
* An array of URL patterns that URLs must match to be enqueued.
|
|
36
39
|
*
|
|
37
|
-
*
|
|
38
|
-
* All remaining keys will be used as request options for the corresponding enqueued {@link Request} objects.
|
|
39
|
-
*
|
|
40
|
-
* The matching is always case-insensitive.
|
|
41
|
-
* If you need case-sensitive matching, use `regexps` property directly.
|
|
42
|
-
*
|
|
43
|
-
* If `globs` is an empty array or `undefined`, and `regexps` are also not defined, then the function
|
|
44
|
-
* enqueues the links with the same subdomain.
|
|
45
|
-
*/
|
|
46
|
-
globs?: readonly GlobInput[];
|
|
47
|
-
/**
|
|
48
|
-
* An array of glob pattern strings, regexp patterns or plain objects
|
|
49
|
-
* containing patterns matching URLs that will **never** be enqueued.
|
|
50
|
-
*
|
|
51
|
-
* The plain objects must include either the `glob` property or the `regexp` property.
|
|
52
|
-
* All remaining keys will be used as request options for the corresponding enqueued {@link Request} objects.
|
|
40
|
+
* Accepts glob pattern strings, `{ glob: string }` objects, `RegExp` instances, or `{ regexp: RegExp }` objects.
|
|
53
41
|
*
|
|
54
42
|
* Glob matching is always case-insensitive.
|
|
55
|
-
* If you need case-sensitive matching,
|
|
56
|
-
*/
|
|
57
|
-
exclude?: readonly (GlobInput | RegExpInput)[];
|
|
58
|
-
/**
|
|
59
|
-
* An array of regular expressions or plain objects
|
|
60
|
-
* containing regular expressions matching the URLs to be enqueued.
|
|
43
|
+
* If you need case-sensitive matching, use a `RegExp`.
|
|
61
44
|
*
|
|
62
|
-
* The
|
|
63
|
-
*
|
|
45
|
+
* The patterns are combined with the {@link EnqueueLinksOptions.strategy|`strategy`} using AND logic - a URL
|
|
46
|
+
* must match at least one `include` pattern **and** satisfy the strategy to be enqueued. To match URLs across
|
|
47
|
+
* hostnames, pass an explicit {@link EnqueueStrategy.All} strategy.
|
|
64
48
|
*
|
|
65
|
-
* If `
|
|
66
|
-
*
|
|
49
|
+
* If `undefined`, the links are enqueued based on the {@link EnqueueLinksOptions.strategy|`strategy`} alone.
|
|
50
|
+
* Passing an empty array is not allowed.
|
|
67
51
|
*/
|
|
68
|
-
|
|
52
|
+
include?: readonly UrlPatternInput[];
|
|
69
53
|
/**
|
|
70
|
-
*
|
|
71
|
-
* Please use `globs` or `regexps` instead.
|
|
72
|
-
*
|
|
73
|
-
* An array of {@link PseudoUrl} strings or plain objects
|
|
74
|
-
* containing {@link PseudoUrl} strings matching the URLs to be enqueued.
|
|
75
|
-
*
|
|
76
|
-
* The plain objects must include at least the `purl` property, which holds the pseudo-URL string.
|
|
77
|
-
* All remaining keys will be used as request options for the corresponding enqueued {@link Request} objects.
|
|
78
|
-
*
|
|
79
|
-
* With a pseudo-URL string, the matching is always case-insensitive.
|
|
80
|
-
* If you need case-sensitive matching, use `regexps` property directly.
|
|
54
|
+
* An array of URL patterns. Matching URLs will **not** be enqueued.
|
|
81
55
|
*
|
|
82
|
-
*
|
|
83
|
-
* enqueues the links with the same subdomain.
|
|
56
|
+
* Accepts glob pattern strings, `{ glob: string }` objects, `RegExp` instances, or `{ regexp: RegExp }` objects.
|
|
84
57
|
*
|
|
85
|
-
*
|
|
58
|
+
* Glob matching is always case-insensitive.
|
|
59
|
+
* If you need case-sensitive matching, use a `RegExp`.
|
|
86
60
|
*/
|
|
87
|
-
|
|
61
|
+
exclude?: readonly UrlPatternInput[];
|
|
88
62
|
/**
|
|
89
|
-
*
|
|
90
|
-
* to remove
|
|
63
|
+
* After request options are filtered by `include`/`exclude` patterns, this function can be used
|
|
64
|
+
* to remove them or modify their contents such as `userData`, `payload` or, most importantly `uniqueKey`. This is useful
|
|
91
65
|
* when you need to enqueue multiple `Requests` to the queue that share the same URL, but differ in methods or payloads,
|
|
92
66
|
* or to dynamically update or create `userData`.
|
|
93
67
|
*
|
|
94
|
-
* For example: by adding `keepUrlFragment: true` to the
|
|
68
|
+
* For example: by adding `keepUrlFragment: true` to the request options, URL fragments will not be removed
|
|
95
69
|
* when `uniqueKey` is computed.
|
|
96
70
|
*
|
|
97
71
|
* **Example:**
|
|
@@ -105,9 +79,13 @@ export interface EnqueueLinksOptions extends RequestQueueOperationOptions {
|
|
|
105
79
|
* }
|
|
106
80
|
* ```
|
|
107
81
|
*
|
|
108
|
-
* Note that `transformRequestFunction` has
|
|
109
|
-
*
|
|
110
|
-
*
|
|
82
|
+
* Note that `transformRequestFunction` has the highest priority and can overwrite
|
|
83
|
+
* the global `label` option.
|
|
84
|
+
*
|
|
85
|
+
* The function receives a {@link RequestOptions} object and can return either:
|
|
86
|
+
* - The modified {@link RequestOptions} object
|
|
87
|
+
* - `'unchanged'` to keep the original options as-is
|
|
88
|
+
* - A falsy value or `'skip'` to exclude the request from the queue
|
|
111
89
|
*/
|
|
112
90
|
transformRequestFunction?: RequestTransform;
|
|
113
91
|
/**
|
|
@@ -138,10 +116,21 @@ export interface EnqueueLinksOptions extends RequestQueueOperationOptions {
|
|
|
138
116
|
* RobotsTxtFile instance for the current request that triggered the `enqueueLinks`.
|
|
139
117
|
* If provided, disallowed URLs will be ignored.
|
|
140
118
|
*/
|
|
141
|
-
robotsTxtFile?: RobotsTxtFile
|
|
119
|
+
robotsTxtFile?: Pick<RobotsTxtFile, 'isAllowed'>;
|
|
120
|
+
/**
|
|
121
|
+
* Mirrors {@link BasicCrawlerOptions.respectRobotsTxtFile}: pass `false` to disable filtering or
|
|
122
|
+
* `{ userAgent }` to evaluate rules for a specific user-agent. Defaults to `*` when
|
|
123
|
+
* {@link EnqueueLinksOptions.robotsTxtFile|`robotsTxtFile`} is provided.
|
|
124
|
+
*/
|
|
125
|
+
respectRobotsTxtFile?: boolean | {
|
|
126
|
+
userAgent?: string;
|
|
127
|
+
};
|
|
142
128
|
/**
|
|
143
129
|
* When a request is skipped for some reason, you can use this callback to act on it.
|
|
144
|
-
* This is currently fired
|
|
130
|
+
* This is currently fired for requests skipped
|
|
131
|
+
* 1. based on robots.txt file,
|
|
132
|
+
* 2. because they don't match enqueueLinks filters,
|
|
133
|
+
* 3. or because the maxRequestsPerCrawl limit has been reached
|
|
145
134
|
*/
|
|
146
135
|
onSkippedRequest?: SkippedRequestCallback;
|
|
147
136
|
}
|
|
@@ -200,17 +189,16 @@ export declare enum EnqueueStrategy {
|
|
|
200
189
|
* This function enqueues the urls provided to the {@link RequestQueue} provided. If you want to automatically find and enqueue links,
|
|
201
190
|
* you should use the context-aware `enqueueLinks` function provided on the crawler contexts.
|
|
202
191
|
*
|
|
203
|
-
* Optionally, the function allows you to filter the target links' URLs using an array of
|
|
204
|
-
* and override settings of the enqueued {@link Request} objects.
|
|
192
|
+
* Optionally, the function allows you to filter the target links' URLs using an array of glob or regexp patterns.
|
|
205
193
|
*
|
|
206
194
|
* **Example usage**
|
|
207
195
|
*
|
|
208
196
|
* ```javascript
|
|
209
197
|
* await enqueueLinks({
|
|
210
198
|
* urls: aListOfFoundUrls,
|
|
211
|
-
*
|
|
199
|
+
* requestManager,
|
|
212
200
|
* selector: 'a.product-detail',
|
|
213
|
-
*
|
|
201
|
+
* include: [
|
|
214
202
|
* 'https://www.example.com/handbags/*',
|
|
215
203
|
* 'https://www.example.com/purses/*'
|
|
216
204
|
* ],
|
|
@@ -220,7 +208,11 @@ export declare enum EnqueueStrategy {
|
|
|
220
208
|
* @param options All `enqueueLinks()` parameters are passed via an options object.
|
|
221
209
|
* @returns Promise that resolves to {@link BatchAddRequestsResult} object.
|
|
222
210
|
*/
|
|
223
|
-
export declare function enqueueLinks(options: SetRequired<EnqueueLinksOptions, '
|
|
211
|
+
export declare function enqueueLinks(options: SetRequired<Omit<EnqueueLinksOptions, 'requestManager'>, 'urls'> & {
|
|
212
|
+
requestManager: {
|
|
213
|
+
addRequestsBatched: (requests: Request<Dictionary>[], options: AddRequestsBatchedOptions) => Promise<AddRequestsBatchedResult>;
|
|
214
|
+
};
|
|
215
|
+
}): Promise<BatchAddRequestsResult>;
|
|
224
216
|
/**
|
|
225
217
|
* @internal
|
|
226
218
|
* This method helps resolve the baseUrl that will be used for filtering in {@link enqueueLinks}.
|
|
@@ -239,4 +231,3 @@ export interface ResolveBaseUrl {
|
|
|
239
231
|
originalRequestUrl: string;
|
|
240
232
|
finalRequestUrl?: string;
|
|
241
233
|
}
|
|
242
|
-
//# sourceMappingURL=enqueue_links.d.ts.map
|