@crawlee/core 4.0.0-beta.13 → 4.0.0-beta.131
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 +67 -172
- package/autoscaling/autoscaled_pool.js +182 -329
- package/autoscaling/concurrency_system.d.ts +268 -0
- package/autoscaling/concurrency_system.js +362 -0
- package/autoscaling/cpu_load_signal.d.ts +43 -0
- package/autoscaling/cpu_load_signal.js +47 -0
- package/autoscaling/event_loop_load_signal.d.ts +51 -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 +100 -0
- package/autoscaling/load_signal.js +105 -0
- package/autoscaling/memory_load_signal.d.ts +47 -0
- package/autoscaling/memory_load_signal.js +106 -0
- package/autoscaling/snapshotter.d.ts +58 -163
- package/autoscaling/snapshotter.js +45 -263
- package/autoscaling/storage_backend_load_signal.d.ts +56 -0
- package/autoscaling/storage_backend_load_signal.js +73 -0
- package/autoscaling/system_status.d.ts +67 -89
- package/autoscaling/system_status.js +92 -122
- 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 -223
- package/configuration.js +170 -222
- package/cookie_utils.d.ts +3 -2
- package/cookie_utils.js +18 -7
- package/crawlers/context_pipeline.d.ts +10 -1
- package/crawlers/context_pipeline.js +31 -8
- package/crawlers/crawler_commons.d.ts +90 -129
- package/crawlers/crawler_commons.js +1 -116
- package/crawlers/error_snapshotter.d.ts +2 -5
- package/crawlers/error_snapshotter.js +7 -8
- package/crawlers/error_tracker.d.ts +0 -1
- package/crawlers/error_tracker.js +0 -1
- package/crawlers/index.d.ts +1 -3
- package/crawlers/index.js +0 -3
- package/crawlers/internals/types.d.ts +0 -1
- package/crawlers/internals/types.js +0 -1
- package/crawlers/statistics.d.ts +187 -63
- package/crawlers/statistics.js +354 -164
- package/debug.d.ts +36 -0
- package/debug.js +70 -0
- package/enqueue_links/enqueue_links.d.ts +68 -154
- package/enqueue_links/enqueue_links.js +38 -210
- package/enqueue_links/index.d.ts +0 -1
- package/enqueue_links/index.js +0 -1
- package/enqueue_links/shared.d.ts +52 -26
- package/enqueue_links/shared.js +115 -66
- package/errors.d.ts +72 -4
- package/errors.js +89 -5
- package/events/event_manager.d.ts +35 -9
- package/events/event_manager.js +12 -13
- package/events/index.d.ts +0 -1
- package/events/index.js +0 -1
- package/events/local_event_manager.d.ts +15 -3
- package/events/local_event_manager.js +39 -13
- package/http.d.ts +9 -0
- package/http.js +28 -0
- package/index.d.ts +7 -4
- package/index.js +6 -3
- package/iterables.d.ts +79 -0
- package/iterables.js +134 -0
- package/log.d.ts +82 -3
- package/log.js +106 -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 +38 -0
- package/memory-storage/memory-storage.js +130 -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 +108 -0
- package/memory-storage/resource-clients/key-value-store.d.ts +63 -0
- package/memory-storage/resource-clients/key-value-store.js +201 -0
- package/memory-storage/resource-clients/request-queue.d.ts +77 -0
- package/memory-storage/resource-clients/request-queue.js +409 -0
- package/memory-storage/utils.d.ts +16 -0
- package/memory-storage/utils.js +41 -0
- package/owned_or_injected.d.ts +58 -0
- package/owned_or_injected.js +98 -0
- package/package.json +14 -13
- package/proxy_configuration.d.ts +24 -132
- package/proxy_configuration.js +32 -147
- package/recoverable_state.d.ts +155 -0
- package/recoverable_state.js +231 -0
- package/request.d.ts +80 -16
- package/request.js +147 -68
- package/router.d.ts +193 -21
- package/router.js +188 -43
- package/serialization.d.ts +0 -1
- package/serialization.js +15 -15
- package/service_locator.d.ts +165 -0
- package/service_locator.js +253 -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 +35 -88
- package/session_pool/session.js +101 -159
- package/session_pool/session_pool.d.ts +73 -91
- package/session_pool/session_pool.js +172 -165
- package/storages/batched_adds.d.ts +37 -0
- package/storages/batched_adds.js +73 -0
- package/storages/dataset.d.ts +114 -54
- package/storages/dataset.js +291 -148
- package/storages/index.d.ts +10 -8
- package/storages/index.js +8 -8
- package/storages/key_value_store.d.ts +185 -42
- package/storages/key_value_store.js +445 -169
- 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 +22 -0
- package/storages/request_dedup_cache.js +48 -0
- package/storages/request_list.d.ts +52 -115
- package/storages/request_list.js +183 -152
- package/storages/request_loader.d.ts +101 -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 +97 -0
- package/storages/request_manager_tandem.js +197 -0
- package/storages/request_queue.d.ts +290 -47
- package/storages/request_queue.js +762 -216
- package/storages/{sitemap_request_list.d.ts → sitemap_request_loader.d.ts} +45 -89
- package/storages/sitemap_request_loader.js +438 -0
- package/storages/storage_instance_manager.d.ts +87 -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/throttling_request_manager.d.ts +239 -0
- package/storages/throttling_request_manager.js +646 -0
- package/storages/transaction.d.ts +252 -0
- package/storages/transaction.js +251 -0
- package/storages/utils.d.ts +59 -11
- package/storages/utils.js +75 -15
- 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/url.d.ts +9 -0
- package/url.js +11 -0
- package/validators.d.ts +22 -18
- package/validators.js +13 -18
- 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/context_pipeline.d.ts.map +0 -1
- package/crawlers/context_pipeline.js.map +0 -1
- package/crawlers/crawler_commons.d.ts.map +0 -1
- package/crawlers/crawler_commons.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/internals/types.d.ts.map +0 -1
- package/crawlers/internals/types.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 -140
- package/http_clients/base-http-client.d.ts.map +0 -1
- package/http_clients/base-http-client.js +0 -40
- 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 -20
- package/http_clients/got-scraping-http-client.d.ts.map +0 -1
- package/http_clients/got-scraping-http-client.js +0 -82
- 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 +0 -13
- package/storages/access_checking.d.ts.map +0 -1
- package/storages/access_checking.js +0 -14
- 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 -308
- 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 +0 -430
- 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
|
@@ -1,19 +1,63 @@
|
|
|
1
|
-
import type { Dictionary } from '@crawlee/types';
|
|
2
|
-
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
7
|
-
import type { Log } from '../log.js';
|
|
8
|
-
import type { ProxyInfo } from '../proxy_configuration.js';
|
|
9
|
-
import type { Request, Source } from '../request.js';
|
|
10
|
-
import type { Session } from '../session_pool/session.js';
|
|
1
|
+
import type { Dictionary, HttpRequestOptions, ISession, ProxyInfo, SendRequestOptions } from '@crawlee/types';
|
|
2
|
+
import type { ReadonlyDeep } from 'type-fest';
|
|
3
|
+
import type { EnqueueUrlsOptions } from '../enqueue_links/enqueue_links.js';
|
|
4
|
+
import type { CrawleeLogger } from '../log.js';
|
|
5
|
+
import type { Request, RequestOptions, Source } from '../request.js';
|
|
6
|
+
import type { StorageIdentifier } from '../storages/storage_instance_manager.js';
|
|
11
7
|
import type { Dataset } from '../storages/dataset.js';
|
|
12
|
-
import { KeyValueStore
|
|
13
|
-
import type {
|
|
8
|
+
import type { KeyValueStore } from '../storages/key_value_store.js';
|
|
9
|
+
import type { AddRequestsBatchedResult } from '../storages/request_queue.js';
|
|
14
10
|
/** @internal */
|
|
15
11
|
export type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
16
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* A request input (URL string, request-options object, or {@link Request}) whose `userData` is typed
|
|
14
|
+
* according to its `label`, based on a router's route map.
|
|
15
|
+
*
|
|
16
|
+
* When the route map is open (the default `Record<string, ...>`), this is just the regular loose
|
|
17
|
+
* {@link Source} input. When the map declares concrete labels, providing a `label` requires the matching
|
|
18
|
+
* `userData` shape and rejects labels not present in the map; unlabeled requests keep loose `userData`.
|
|
19
|
+
*/
|
|
20
|
+
export type LabeledSource<Routes extends Record<keyof Routes, Dictionary>> = string extends keyof Routes ? string | Source : string | Request | ({
|
|
21
|
+
requestsFromUrl?: string;
|
|
22
|
+
regex?: RegExp;
|
|
23
|
+
} & ({
|
|
24
|
+
[Label in keyof Routes & string]: Omit<Partial<RequestOptions<Routes[Label]>>, 'label'> & {
|
|
25
|
+
label: Label;
|
|
26
|
+
};
|
|
27
|
+
}[keyof Routes & string] | (Omit<Partial<RequestOptions>, 'label'> & {
|
|
28
|
+
label?: undefined;
|
|
29
|
+
})));
|
|
30
|
+
/**
|
|
31
|
+
* The iterable/array of {@link LabeledSource} inputs accepted by the label-aware `addRequests`/`run`
|
|
32
|
+
* methods of a crawler bound to a typed router.
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
export type TypedRequestsLike<Routes extends Record<keyof Routes, Dictionary>> = AsyncIterable<LabeledSource<Routes>> | Iterable<LabeledSource<Routes>> | LabeledSource<Routes>[];
|
|
36
|
+
/**
|
|
37
|
+
* The label-aware `addRequests` method signature exposed on a request handler's context when the crawler is
|
|
38
|
+
* bound to a typed router. Mirrors {@link RestrictedCrawlingContext.addRequests} with typed sources.
|
|
39
|
+
*/
|
|
40
|
+
export type TypedContextAddRequests<Routes extends Record<keyof Routes, Dictionary>> = (requestsLike: ReadonlyDeep<LabeledSource<Routes>[]>, options?: ReadonlyDeep<EnqueueUrlsOptions>) => Promise<AddRequestsBatchedResult>;
|
|
41
|
+
/**
|
|
42
|
+
* An `enqueueLinks`-options object with its `label`/`userData` retyped according to a router's route map: a
|
|
43
|
+
* declared `label` requires the matching `userData` shape (unknown labels are rejected), while unlabeled
|
|
44
|
+
* calls keep loose `userData`. Returns the options unchanged when the route map is open (the default).
|
|
45
|
+
*/
|
|
46
|
+
type TypedEnqueueLinksOptions<Options, Routes extends Record<keyof Routes, Dictionary>> = string extends keyof Routes ? Options : Omit<Options, 'label' | 'userData'> & ({
|
|
47
|
+
[Label in keyof Routes & string]: {
|
|
48
|
+
label: Label;
|
|
49
|
+
userData?: Routes[Label];
|
|
50
|
+
};
|
|
51
|
+
}[keyof Routes & string] | {
|
|
52
|
+
label?: undefined;
|
|
53
|
+
userData?: Dictionary;
|
|
54
|
+
});
|
|
55
|
+
/**
|
|
56
|
+
* Transforms a context's existing `enqueueLinks` method so that the `label`/`userData` in its options follow
|
|
57
|
+
* the router's route map, while preserving everything else about the signature (argument optionality and
|
|
58
|
+
* return type, which differ between crawler types).
|
|
59
|
+
*/
|
|
60
|
+
export type TypedContextEnqueueLinks<EnqueueLinks, Routes extends Record<keyof Routes, Dictionary>> = EnqueueLinks extends (options?: infer Options) => infer Result ? (options?: TypedEnqueueLinksOptions<Options, Routes>) => Result : EnqueueLinks extends (options: infer Options) => infer Result ? (options: TypedEnqueueLinksOptions<Options, Routes>) => Result : EnqueueLinks;
|
|
17
61
|
export type WithRequired<T, K extends keyof T> = T & {
|
|
18
62
|
[P in K]-?: T[P];
|
|
19
63
|
};
|
|
@@ -24,7 +68,7 @@ export type LoadedContext<Context extends RestrictedCrawlingContext> = IsAny<Con
|
|
|
24
68
|
} & Omit<Context, 'request'>;
|
|
25
69
|
export interface RestrictedCrawlingContext<UserData extends Dictionary = Dictionary> {
|
|
26
70
|
id: string;
|
|
27
|
-
session
|
|
71
|
+
session: ISession;
|
|
28
72
|
/**
|
|
29
73
|
* An object with information about currently used proxy by the crawler
|
|
30
74
|
* and configured by the {@link ProxyConfiguration} class.
|
|
@@ -41,39 +85,17 @@ export interface RestrictedCrawlingContext<UserData extends Dictionary = Diction
|
|
|
41
85
|
*
|
|
42
86
|
* @param [data] Data to be pushed to the default dataset.
|
|
43
87
|
*/
|
|
44
|
-
pushData(data: ReadonlyDeep<Parameters<Dataset['pushData']>[0]>,
|
|
88
|
+
pushData(data: ReadonlyDeep<Parameters<Dataset['pushData']>[0]>, datasetIdentifier?: string | StorageIdentifier): Promise<void>;
|
|
45
89
|
/**
|
|
46
|
-
*
|
|
47
|
-
* currently used by the crawler.
|
|
48
|
-
*
|
|
49
|
-
* Optionally, the function allows you to filter the target links' URLs using an array of globs or regular expressions
|
|
50
|
-
* and override settings of the enqueued {@link Request} objects.
|
|
90
|
+
* Add requests directly to the request queue currently used by the crawler.
|
|
51
91
|
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* **Example usage**
|
|
56
|
-
*
|
|
57
|
-
* ```ts
|
|
58
|
-
* async requestHandler({ enqueueLinks }) {
|
|
59
|
-
* await enqueueLinks({
|
|
60
|
-
* globs: [
|
|
61
|
-
* 'https://www.example.com/handbags/*',
|
|
62
|
-
* ],
|
|
63
|
-
* });
|
|
64
|
-
* },
|
|
65
|
-
* ```
|
|
66
|
-
*
|
|
67
|
-
* @param [options] All `enqueueLinks()` parameters are passed via an options object.
|
|
68
|
-
*/
|
|
69
|
-
enqueueLinks: (options: ReadonlyDeep<Omit<SetRequired<EnqueueLinksOptions, 'urls'>, 'requestQueue' | 'robotsTxtFile'>>) => Promise<unknown>;
|
|
70
|
-
/**
|
|
71
|
-
* Add requests directly to the request queue.
|
|
92
|
+
* Optionally, the function allows you to filter the target URLs using an array of glob or regexp patterns,
|
|
93
|
+
* the same way {@link CrawlingContext.enqueueLinks|`enqueueLinks`} does for extracted links.
|
|
72
94
|
*
|
|
73
95
|
* @param requests The requests to add
|
|
74
96
|
* @param options Options for the request queue
|
|
75
97
|
*/
|
|
76
|
-
addRequests: (requestsLike: ReadonlyDeep<(string | Source)[]>, options?: ReadonlyDeep<
|
|
98
|
+
addRequests: (requestsLike: ReadonlyDeep<(string | Source)[]>, options?: ReadonlyDeep<EnqueueUrlsOptions>) => Promise<AddRequestsBatchedResult>;
|
|
77
99
|
/**
|
|
78
100
|
* Returns the state - a piece of mutable persistent data shared across all the request handler runs.
|
|
79
101
|
*/
|
|
@@ -81,42 +103,15 @@ export interface RestrictedCrawlingContext<UserData extends Dictionary = Diction
|
|
|
81
103
|
/**
|
|
82
104
|
* Get a key-value store with given name or id, or the default one for the crawler.
|
|
83
105
|
*/
|
|
84
|
-
getKeyValueStore: (
|
|
106
|
+
getKeyValueStore: (identifier?: string | StorageIdentifier) => Promise<Pick<KeyValueStore, 'id' | 'name' | 'getValue' | 'getAutoSavedValue' | 'setValue' | 'getPublicUrl'>>;
|
|
85
107
|
/**
|
|
86
108
|
* A preconfigured logger for the request handler.
|
|
87
109
|
*/
|
|
88
|
-
log:
|
|
110
|
+
log: CrawleeLogger;
|
|
89
111
|
}
|
|
90
112
|
export interface CrawlingContext<UserData extends Dictionary = Dictionary> extends RestrictedCrawlingContext<UserData> {
|
|
91
113
|
/**
|
|
92
|
-
*
|
|
93
|
-
* currently used by the crawler.
|
|
94
|
-
*
|
|
95
|
-
* Optionally, the function allows you to filter the target links' URLs using an array of globs or regular expressions
|
|
96
|
-
* and override settings of the enqueued {@link Request} objects.
|
|
97
|
-
*
|
|
98
|
-
* Check out the [Crawl a website with relative links](https://crawlee.dev/js/docs/examples/crawl-relative-links) example
|
|
99
|
-
* for more details regarding its usage.
|
|
100
|
-
*
|
|
101
|
-
* **Example usage**
|
|
102
|
-
*
|
|
103
|
-
* ```ts
|
|
104
|
-
* async requestHandler({ enqueueLinks }) {
|
|
105
|
-
* await enqueueLinks({
|
|
106
|
-
* globs: [
|
|
107
|
-
* 'https://www.example.com/handbags/*',
|
|
108
|
-
* ],
|
|
109
|
-
* });
|
|
110
|
-
* },
|
|
111
|
-
* ```
|
|
112
|
-
*
|
|
113
|
-
* @param [options] All `enqueueLinks()` parameters are passed via an options object.
|
|
114
|
-
* @returns Promise that resolves to {@link BatchAddRequestsResult} object.
|
|
115
|
-
*/
|
|
116
|
-
enqueueLinks(options: ReadonlyDeep<Omit<SetRequired<EnqueueLinksOptions, 'urls'>, 'requestQueue' | 'robotsTxtFile'>> & Pick<EnqueueLinksOptions, 'requestQueue' | 'robotsTxtFile'>): Promise<unknown>;
|
|
117
|
-
/**
|
|
118
|
-
* Fires HTTP request via [`got-scraping`](https://crawlee.dev/js/docs/guides/got-scraping), allowing to override the request
|
|
119
|
-
* options on the fly.
|
|
114
|
+
* Fires HTTP request via the internal HTTP client, allowing to override the request options on the fly.
|
|
120
115
|
*
|
|
121
116
|
* This is handy when you work with a browser crawler but want to execute some requests outside it (e.g. API requests).
|
|
122
117
|
* Check the [Skipping navigations for certain requests](https://crawlee.dev/js/docs/examples/skip-navigation) example for
|
|
@@ -131,68 +126,34 @@ export interface CrawlingContext<UserData extends Dictionary = Dictionary> exten
|
|
|
131
126
|
* },
|
|
132
127
|
* ```
|
|
133
128
|
*/
|
|
134
|
-
sendRequest(
|
|
129
|
+
sendRequest: (requestOverrides?: Partial<HttpRequestOptions>, optionsOverrides?: SendRequestOptions) => Promise<Response>;
|
|
135
130
|
/**
|
|
136
131
|
* Register a function to be called at the very end of the request handling process. This is useful for resources that should be accessible to error handlers, for instance.
|
|
132
|
+
*
|
|
133
|
+
* The callback runs *outside* the request's storage transaction, so storage writes made here are
|
|
134
|
+
* applied immediately and are **not** rolled back when the request fails. In
|
|
135
|
+
* {@link AdaptivePlaywrightCrawler} it also runs once per request handler attempt, so a write
|
|
136
|
+
* here can land more than once for a single request. Push results from the request handler itself.
|
|
137
137
|
*/
|
|
138
138
|
registerDeferredCleanup(cleanup: () => Promise<unknown>): void;
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* A partial implementation of {@link RestrictedCrawlingContext} that stores parameters of calls to context methods for later inspection.
|
|
142
|
-
*
|
|
143
|
-
* @experimental
|
|
144
|
-
*/
|
|
145
|
-
export declare class RequestHandlerResult {
|
|
146
|
-
private config;
|
|
147
|
-
private crawleeStateKey;
|
|
148
|
-
private _keyValueStoreChanges;
|
|
149
|
-
private pushDataCalls;
|
|
150
|
-
private addRequestsCalls;
|
|
151
|
-
private enqueueLinksCalls;
|
|
152
|
-
constructor(config: Configuration, crawleeStateKey: string);
|
|
153
139
|
/**
|
|
154
|
-
*
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
*
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
*
|
|
170
|
-
*/
|
|
171
|
-
get datasetItems(): ReadonlyDeep<{
|
|
172
|
-
item: Dictionary;
|
|
173
|
-
datasetIdOrName?: string;
|
|
174
|
-
}[]>;
|
|
175
|
-
/**
|
|
176
|
-
* URLs enqueued to the request queue by a request handler, either via {@link RestrictedCrawlingContext.addRequests} or {@link RestrictedCrawlingContext.enqueueLinks}
|
|
177
|
-
*/
|
|
178
|
-
get enqueuedUrls(): ReadonlyDeep<{
|
|
179
|
-
url: string;
|
|
180
|
-
label?: string;
|
|
181
|
-
}[]>;
|
|
182
|
-
/**
|
|
183
|
-
* URL lists enqueued to the request queue by a request handler via {@link RestrictedCrawlingContext.addRequests} using the `requestsFromUrl` option.
|
|
140
|
+
* Gives the current request `secs` more seconds to finish, for when how long it needs is only apparent
|
|
141
|
+
* once it is already running - a listing page that turns out to have far more to scroll through than
|
|
142
|
+
* usual, say. Prefer `requestHandlerTimeoutSecs`, or a per-route override via
|
|
143
|
+
* {@link Router.addHandler|`router.addHandler`}, whenever the time needed is known up front.
|
|
144
|
+
*
|
|
145
|
+
* ```ts
|
|
146
|
+
* router.addHandler('LIST', async ({ extendTimeout, page }) => {
|
|
147
|
+
* const pageCount = await countPages(page);
|
|
148
|
+
* extendTimeout(pageCount * 10);
|
|
149
|
+
* await scrapeAllPages(page);
|
|
150
|
+
* });
|
|
151
|
+
* ```
|
|
152
|
+
*
|
|
153
|
+
* Extends the request handler's own timeout and the crawler's internal one together, so the extension
|
|
154
|
+
* is not immediately undone by the latter. Calling it from a handler that has already timed out does
|
|
155
|
+
* nothing.
|
|
184
156
|
*/
|
|
185
|
-
|
|
186
|
-
listUrl: string;
|
|
187
|
-
label?: string;
|
|
188
|
-
}[]>;
|
|
189
|
-
pushData: RestrictedCrawlingContext['pushData'];
|
|
190
|
-
enqueueLinks: RestrictedCrawlingContext['enqueueLinks'];
|
|
191
|
-
addRequests: RestrictedCrawlingContext['addRequests'];
|
|
192
|
-
useState: RestrictedCrawlingContext['useState'];
|
|
193
|
-
getKeyValueStore: RestrictedCrawlingContext['getKeyValueStore'];
|
|
194
|
-
private idOrDefault;
|
|
195
|
-
private getKeyValueStoreChangedValue;
|
|
196
|
-
private setKeyValueStoreChangedValue;
|
|
157
|
+
extendTimeout(secs: number): void;
|
|
197
158
|
}
|
|
198
|
-
|
|
159
|
+
export {};
|
|
@@ -1,116 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* A partial implementation of {@link RestrictedCrawlingContext} that stores parameters of calls to context methods for later inspection.
|
|
4
|
-
*
|
|
5
|
-
* @experimental
|
|
6
|
-
*/
|
|
7
|
-
export class RequestHandlerResult {
|
|
8
|
-
config;
|
|
9
|
-
crawleeStateKey;
|
|
10
|
-
_keyValueStoreChanges = {};
|
|
11
|
-
pushDataCalls = [];
|
|
12
|
-
addRequestsCalls = [];
|
|
13
|
-
enqueueLinksCalls = [];
|
|
14
|
-
constructor(config, crawleeStateKey) {
|
|
15
|
-
this.config = config;
|
|
16
|
-
this.crawleeStateKey = crawleeStateKey;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* A record of calls to {@link RestrictedCrawlingContext.pushData}, {@link RestrictedCrawlingContext.addRequests}, {@link RestrictedCrawlingContext.enqueueLinks} made by a request handler.
|
|
20
|
-
*/
|
|
21
|
-
get calls() {
|
|
22
|
-
return {
|
|
23
|
-
pushData: this.pushDataCalls,
|
|
24
|
-
addRequests: this.addRequestsCalls,
|
|
25
|
-
enqueueLinks: this.enqueueLinksCalls,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* A record of changes made to key-value stores by a request handler.
|
|
30
|
-
*/
|
|
31
|
-
get keyValueStoreChanges() {
|
|
32
|
-
return this._keyValueStoreChanges;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Items added to datasets by a request handler.
|
|
36
|
-
*/
|
|
37
|
-
get datasetItems() {
|
|
38
|
-
return this.pushDataCalls.flatMap(([data, datasetIdOrName]) => (Array.isArray(data) ? data : [data]).map((item) => ({ item, datasetIdOrName })));
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* URLs enqueued to the request queue by a request handler, either via {@link RestrictedCrawlingContext.addRequests} or {@link RestrictedCrawlingContext.enqueueLinks}
|
|
42
|
-
*/
|
|
43
|
-
get enqueuedUrls() {
|
|
44
|
-
const result = [];
|
|
45
|
-
for (const [options] of this.enqueueLinksCalls) {
|
|
46
|
-
result.push(...(options?.urls?.map((url) => ({ url, label: options?.label })) ?? []));
|
|
47
|
-
}
|
|
48
|
-
for (const [requests] of this.addRequestsCalls) {
|
|
49
|
-
for (const request of requests) {
|
|
50
|
-
if (typeof request === 'object' &&
|
|
51
|
-
(!('requestsFromUrl' in request) || request.requestsFromUrl !== undefined) &&
|
|
52
|
-
request.url !== undefined) {
|
|
53
|
-
result.push({ url: request.url, label: request.label });
|
|
54
|
-
}
|
|
55
|
-
else if (typeof request === 'string') {
|
|
56
|
-
result.push({ url: request });
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return result;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* URL lists enqueued to the request queue by a request handler via {@link RestrictedCrawlingContext.addRequests} using the `requestsFromUrl` option.
|
|
64
|
-
*/
|
|
65
|
-
get enqueuedUrlLists() {
|
|
66
|
-
const result = [];
|
|
67
|
-
for (const [requests] of this.addRequestsCalls) {
|
|
68
|
-
for (const request of requests) {
|
|
69
|
-
if (typeof request === 'object' &&
|
|
70
|
-
'requestsFromUrl' in request &&
|
|
71
|
-
request.requestsFromUrl !== undefined) {
|
|
72
|
-
result.push({ listUrl: request.requestsFromUrl, label: request.label });
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return result;
|
|
77
|
-
}
|
|
78
|
-
pushData = async (data, datasetIdOrName) => {
|
|
79
|
-
this.pushDataCalls.push([data, datasetIdOrName]);
|
|
80
|
-
};
|
|
81
|
-
enqueueLinks = async (options) => {
|
|
82
|
-
this.enqueueLinksCalls.push([options]);
|
|
83
|
-
};
|
|
84
|
-
addRequests = async (requests, options = {}) => {
|
|
85
|
-
this.addRequestsCalls.push([requests, options]);
|
|
86
|
-
};
|
|
87
|
-
useState = async (defaultValue) => {
|
|
88
|
-
const store = await this.getKeyValueStore(undefined);
|
|
89
|
-
return await store.getAutoSavedValue(this.crawleeStateKey, defaultValue);
|
|
90
|
-
};
|
|
91
|
-
getKeyValueStore = async (idOrName) => {
|
|
92
|
-
const store = await KeyValueStore.open(idOrName, { config: this.config });
|
|
93
|
-
return {
|
|
94
|
-
id: this.idOrDefault(idOrName),
|
|
95
|
-
name: idOrName,
|
|
96
|
-
getValue: async (key) => this.getKeyValueStoreChangedValue(idOrName, key) ?? (await store.getValue(key)),
|
|
97
|
-
setValue: async (key, value, options) => {
|
|
98
|
-
this.setKeyValueStoreChangedValue(idOrName, key, value, options);
|
|
99
|
-
},
|
|
100
|
-
getAutoSavedValue: store.getAutoSavedValue.bind(store),
|
|
101
|
-
getPublicUrl: store.getPublicUrl.bind(store),
|
|
102
|
-
};
|
|
103
|
-
};
|
|
104
|
-
idOrDefault = (idOrName) => idOrName ?? this.config.get('defaultKeyValueStoreId');
|
|
105
|
-
getKeyValueStoreChangedValue = (idOrName, key) => {
|
|
106
|
-
const id = this.idOrDefault(idOrName);
|
|
107
|
-
this._keyValueStoreChanges[id] ??= {};
|
|
108
|
-
return this.keyValueStoreChanges[id][key]?.changedValue ?? null;
|
|
109
|
-
};
|
|
110
|
-
setKeyValueStoreChangedValue = (idOrName, key, changedValue, options) => {
|
|
111
|
-
const id = this.idOrDefault(idOrName);
|
|
112
|
-
this._keyValueStoreChanges[id] ??= {};
|
|
113
|
-
this._keyValueStoreChanges[id][key] = { changedValue, options };
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
//# sourceMappingURL=crawler_commons.js.map
|
|
1
|
+
export {};
|
|
@@ -25,9 +25,7 @@ interface ErrorSnapshot {
|
|
|
25
25
|
* ```ts
|
|
26
26
|
* const crawler = new BasicCrawler({
|
|
27
27
|
* // ...
|
|
28
|
-
*
|
|
29
|
-
* saveErrorSnapshots: true,
|
|
30
|
-
* },
|
|
28
|
+
* statistics: new Statistics({ saveErrorSnapshots: true }),
|
|
31
29
|
* });
|
|
32
30
|
* ```
|
|
33
31
|
*/
|
|
@@ -48,7 +46,7 @@ export declare class ErrorSnapshotter {
|
|
|
48
46
|
*/
|
|
49
47
|
contextCaptureSnapshot(context: BrowserCrawlingContext, fileName: string): Promise<SnapshotResult | undefined>;
|
|
50
48
|
/**
|
|
51
|
-
* Save the HTML snapshot of the page, and return the
|
|
49
|
+
* Save the HTML snapshot of the page, and return the key it was stored under.
|
|
52
50
|
*/
|
|
53
51
|
saveHTMLSnapshot(html: string, keyValueStore: Pick<KeyValueStore, 'setValue'>, fileName: string): Promise<string | undefined>;
|
|
54
52
|
/**
|
|
@@ -57,4 +55,3 @@ export declare class ErrorSnapshotter {
|
|
|
57
55
|
generateFilename(error: ErrnoException): string;
|
|
58
56
|
}
|
|
59
57
|
export {};
|
|
60
|
-
//# sourceMappingURL=error_snapshotter.d.ts.map
|
|
@@ -7,9 +7,7 @@ import crypto from 'node:crypto';
|
|
|
7
7
|
* ```ts
|
|
8
8
|
* const crawler = new BasicCrawler({
|
|
9
9
|
* // ...
|
|
10
|
-
*
|
|
11
|
-
* saveErrorSnapshots: true,
|
|
12
|
-
* },
|
|
10
|
+
* statistics: new Statistics({ saveErrorSnapshots: true }),
|
|
13
11
|
* });
|
|
14
12
|
* ```
|
|
15
13
|
*/
|
|
@@ -52,9 +50,9 @@ export class ErrorSnapshotter {
|
|
|
52
50
|
}
|
|
53
51
|
return {
|
|
54
52
|
screenshotFileName,
|
|
55
|
-
screenshotFileUrl: screenshotFileName && keyValueStore.getPublicUrl(screenshotFileName),
|
|
53
|
+
screenshotFileUrl: screenshotFileName && (await keyValueStore.getPublicUrl(screenshotFileName)),
|
|
56
54
|
htmlFileName,
|
|
57
|
-
htmlFileUrl: htmlFileName && keyValueStore.getPublicUrl(htmlFileName),
|
|
55
|
+
htmlFileUrl: htmlFileName && (await keyValueStore.getPublicUrl(htmlFileName)),
|
|
58
56
|
};
|
|
59
57
|
}
|
|
60
58
|
catch {
|
|
@@ -79,12 +77,14 @@ export class ErrorSnapshotter {
|
|
|
79
77
|
}
|
|
80
78
|
}
|
|
81
79
|
/**
|
|
82
|
-
* Save the HTML snapshot of the page, and return the
|
|
80
|
+
* Save the HTML snapshot of the page, and return the key it was stored under.
|
|
83
81
|
*/
|
|
84
82
|
async saveHTMLSnapshot(html, keyValueStore, fileName) {
|
|
85
83
|
try {
|
|
86
84
|
await keyValueStore.setValue(fileName, html, { contentType: 'text/html' });
|
|
87
|
-
|
|
85
|
+
// The record key is `fileName` - returning it with an `.html` suffix (as v3 did,
|
|
86
|
+
// where local storage put the extension in the key) would break `getPublicUrl`.
|
|
87
|
+
return fileName;
|
|
88
88
|
}
|
|
89
89
|
catch {
|
|
90
90
|
return undefined;
|
|
@@ -115,4 +115,3 @@ export class ErrorSnapshotter {
|
|
|
115
115
|
return fileName;
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
|
-
//# sourceMappingURL=error_snapshotter.js.map
|
package/crawlers/index.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
export * from './context_pipeline.js';
|
|
2
|
-
export * from './crawler_commons.js';
|
|
3
|
-
export * from './crawler_utils.js';
|
|
2
|
+
export type * from './crawler_commons.js';
|
|
4
3
|
export * from './statistics.js';
|
|
5
4
|
export * from './error_tracker.js';
|
|
6
5
|
export * from './error_snapshotter.js';
|
|
7
|
-
//# sourceMappingURL=index.d.ts.map
|
package/crawlers/index.js
CHANGED