@crawlee/core 4.0.0-beta.11 → 4.0.0-beta.111
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 +165 -320
- package/autoscaling/client_load_signal.d.ts +55 -0
- package/autoscaling/client_load_signal.js +73 -0
- package/autoscaling/concurrency_system.d.ts +268 -0
- package/autoscaling/concurrency_system.js +351 -0
- package/autoscaling/cpu_load_signal.d.ts +43 -0
- package/autoscaling/cpu_load_signal.js +46 -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 +99 -0
- package/autoscaling/load_signal.js +104 -0
- package/autoscaling/memory_load_signal.d.ts +47 -0
- package/autoscaling/memory_load_signal.js +105 -0
- package/autoscaling/snapshotter.d.ts +58 -163
- package/autoscaling/snapshotter.js +45 -263
- package/autoscaling/system_status.d.ts +62 -84
- 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 +4 -3
- package/cookie_utils.js +22 -13
- package/crawlers/context_pipeline.d.ts +10 -1
- package/crawlers/context_pipeline.js +31 -8
- package/crawlers/crawler_commons.d.ts +90 -83
- package/crawlers/crawler_commons.js +1 -116
- package/crawlers/error_snapshotter.d.ts +1 -4
- package/crawlers/error_snapshotter.js +3 -6
- 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 +91 -41
- package/crawlers/statistics.js +83 -72
- 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 +40 -27
- package/enqueue_links/shared.js +90 -68
- package/errors.d.ts +41 -4
- package/errors.js +50 -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 -3
- package/events/local_event_manager.js +37 -11
- 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 +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 +42 -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 +114 -0
- package/memory-storage/resource-clients/key-value-store.d.ts +63 -0
- package/memory-storage/resource-clients/key-value-store.js +204 -0
- package/memory-storage/resource-clients/request-queue.d.ts +77 -0
- package/memory-storage/resource-clients/request-queue.js +422 -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 +13 -12
- package/proxy_configuration.d.ts +27 -152
- package/proxy_configuration.js +27 -179
- package/recoverable_state.d.ts +111 -0
- package/recoverable_state.js +143 -0
- package/request.d.ts +86 -17
- package/request.js +117 -41
- package/router.d.ts +193 -21
- package/router.js +188 -43
- package/serialization.d.ts +0 -1
- package/serialization.js +9 -11
- package/service_locator.d.ts +147 -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 -86
- package/session_pool/session.js +85 -138
- package/session_pool/session_pool.d.ts +77 -91
- package/session_pool/session_pool.js +159 -147
- package/storages/dataset.d.ts +114 -54
- package/storages/dataset.js +285 -144
- package/storages/index.d.ts +9 -8
- package/storages/index.js +7 -8
- package/storages/key_value_store.d.ts +185 -42
- package/storages/key_value_store.js +424 -151
- 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 -116
- package/storages/request_list.js +158 -133
- 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 +97 -0
- package/storages/request_manager_tandem.js +197 -0
- package/storages/request_queue.d.ts +290 -47
- package/storages/request_queue.js +825 -216
- package/storages/{sitemap_request_list.d.ts → sitemap_request_loader.d.ts} +37 -88
- package/storages/{sitemap_request_list.js → sitemap_request_loader.js} +136 -143
- 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/transaction.d.ts +252 -0
- package/storages/transaction.js +251 -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/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 -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 +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.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
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
3
|
-
import type { OptionsInit, Response as GotResponse } from 'got-scraping';
|
|
1
|
+
import type { Dictionary, HttpRequestOptions, ISession, ProxyInfo, SendRequestOptions } from '@crawlee/types';
|
|
4
2
|
import type { ReadonlyDeep, SetRequired } from 'type-fest';
|
|
5
|
-
import type { Configuration } from '../configuration.js';
|
|
6
3
|
import type { EnqueueLinksOptions } from '../enqueue_links/enqueue_links.js';
|
|
7
|
-
import type {
|
|
8
|
-
import type {
|
|
9
|
-
import type {
|
|
10
|
-
import type { Session } from '../session_pool/session.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 { RequestQueueOperationOptions } from '../storages/
|
|
8
|
+
import type { KeyValueStore } from '../storages/key_value_store.js';
|
|
9
|
+
import type { RequestQueueOperationOptions } 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<RequestQueueOperationOptions>) => Promise<void>;
|
|
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,13 +85,12 @@ 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
90
|
* This function automatically finds and enqueues links from the current page, adding them to the {@link RequestQueue}
|
|
47
91
|
* currently used by the crawler.
|
|
48
92
|
*
|
|
49
|
-
* Optionally, the function allows you to filter the target links' URLs using an array of
|
|
50
|
-
* and override settings of the enqueued {@link Request} objects.
|
|
93
|
+
* Optionally, the function allows you to filter the target links' URLs using an array of glob or regexp patterns.
|
|
51
94
|
*
|
|
52
95
|
* Check out the [Crawl a website with relative links](https://crawlee.dev/js/docs/examples/crawl-relative-links) example
|
|
53
96
|
* for more details regarding its usage.
|
|
@@ -57,7 +100,7 @@ export interface RestrictedCrawlingContext<UserData extends Dictionary = Diction
|
|
|
57
100
|
* ```ts
|
|
58
101
|
* async requestHandler({ enqueueLinks }) {
|
|
59
102
|
* await enqueueLinks({
|
|
60
|
-
*
|
|
103
|
+
* include: [
|
|
61
104
|
* 'https://www.example.com/handbags/*',
|
|
62
105
|
* ],
|
|
63
106
|
* });
|
|
@@ -66,7 +109,7 @@ export interface RestrictedCrawlingContext<UserData extends Dictionary = Diction
|
|
|
66
109
|
*
|
|
67
110
|
* @param [options] All `enqueueLinks()` parameters are passed via an options object.
|
|
68
111
|
*/
|
|
69
|
-
enqueueLinks: (options: ReadonlyDeep<Omit<SetRequired<EnqueueLinksOptions, 'urls'>, '
|
|
112
|
+
enqueueLinks: (options: ReadonlyDeep<Omit<SetRequired<EnqueueLinksOptions, 'urls'>, 'requestManager' | 'robotsTxtFile'>>) => Promise<unknown>;
|
|
70
113
|
/**
|
|
71
114
|
* Add requests directly to the request queue.
|
|
72
115
|
*
|
|
@@ -81,19 +124,18 @@ export interface RestrictedCrawlingContext<UserData extends Dictionary = Diction
|
|
|
81
124
|
/**
|
|
82
125
|
* Get a key-value store with given name or id, or the default one for the crawler.
|
|
83
126
|
*/
|
|
84
|
-
getKeyValueStore: (
|
|
127
|
+
getKeyValueStore: (identifier?: string | StorageIdentifier) => Promise<Pick<KeyValueStore, 'id' | 'name' | 'getValue' | 'getAutoSavedValue' | 'setValue' | 'getPublicUrl'>>;
|
|
85
128
|
/**
|
|
86
129
|
* A preconfigured logger for the request handler.
|
|
87
130
|
*/
|
|
88
|
-
log:
|
|
131
|
+
log: CrawleeLogger;
|
|
89
132
|
}
|
|
90
133
|
export interface CrawlingContext<UserData extends Dictionary = Dictionary> extends RestrictedCrawlingContext<UserData> {
|
|
91
134
|
/**
|
|
92
135
|
* This function automatically finds and enqueues links from the current page, adding them to the {@link RequestQueue}
|
|
93
136
|
* currently used by the crawler.
|
|
94
137
|
*
|
|
95
|
-
* Optionally, the function allows you to filter the target links' URLs using an array of
|
|
96
|
-
* and override settings of the enqueued {@link Request} objects.
|
|
138
|
+
* Optionally, the function allows you to filter the target links' URLs using an array of glob or regexp patterns.
|
|
97
139
|
*
|
|
98
140
|
* Check out the [Crawl a website with relative links](https://crawlee.dev/js/docs/examples/crawl-relative-links) example
|
|
99
141
|
* for more details regarding its usage.
|
|
@@ -103,7 +145,7 @@ export interface CrawlingContext<UserData extends Dictionary = Dictionary> exten
|
|
|
103
145
|
* ```ts
|
|
104
146
|
* async requestHandler({ enqueueLinks }) {
|
|
105
147
|
* await enqueueLinks({
|
|
106
|
-
*
|
|
148
|
+
* include: [
|
|
107
149
|
* 'https://www.example.com/handbags/*',
|
|
108
150
|
* ],
|
|
109
151
|
* });
|
|
@@ -113,10 +155,9 @@ export interface CrawlingContext<UserData extends Dictionary = Dictionary> exten
|
|
|
113
155
|
* @param [options] All `enqueueLinks()` parameters are passed via an options object.
|
|
114
156
|
* @returns Promise that resolves to {@link BatchAddRequestsResult} object.
|
|
115
157
|
*/
|
|
116
|
-
enqueueLinks(options: ReadonlyDeep<Omit<SetRequired<EnqueueLinksOptions, 'urls'>, '
|
|
158
|
+
enqueueLinks(options: ReadonlyDeep<Omit<SetRequired<EnqueueLinksOptions, 'urls'>, 'requestManager' | 'robotsTxtFile'>> & Pick<EnqueueLinksOptions, 'requestManager' | 'robotsTxtFile'>): Promise<unknown>;
|
|
117
159
|
/**
|
|
118
|
-
* Fires HTTP request via
|
|
119
|
-
* options on the fly.
|
|
160
|
+
* Fires HTTP request via the internal HTTP client, allowing to override the request options on the fly.
|
|
120
161
|
*
|
|
121
162
|
* This is handy when you work with a browser crawler but want to execute some requests outside it (e.g. API requests).
|
|
122
163
|
* Check the [Skipping navigations for certain requests](https://crawlee.dev/js/docs/examples/skip-navigation) example for
|
|
@@ -131,68 +172,34 @@ export interface CrawlingContext<UserData extends Dictionary = Dictionary> exten
|
|
|
131
172
|
* },
|
|
132
173
|
* ```
|
|
133
174
|
*/
|
|
134
|
-
sendRequest
|
|
175
|
+
sendRequest: (requestOverrides?: Partial<HttpRequestOptions>, optionsOverrides?: SendRequestOptions) => Promise<Response>;
|
|
135
176
|
/**
|
|
136
177
|
* 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.
|
|
178
|
+
*
|
|
179
|
+
* The callback runs *outside* the request's storage transaction, so storage writes made here are
|
|
180
|
+
* applied immediately and are **not** rolled back when the request fails. In
|
|
181
|
+
* {@link AdaptivePlaywrightCrawler} it also runs once per request handler attempt, so a write
|
|
182
|
+
* here can land more than once for a single request. Push results from the request handler itself.
|
|
137
183
|
*/
|
|
138
184
|
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
|
-
/**
|
|
154
|
-
* A record of calls to {@link RestrictedCrawlingContext.pushData}, {@link RestrictedCrawlingContext.addRequests}, {@link RestrictedCrawlingContext.enqueueLinks} made by a request handler.
|
|
155
|
-
*/
|
|
156
|
-
get calls(): ReadonlyDeep<{
|
|
157
|
-
pushData: Parameters<RestrictedCrawlingContext['pushData']>[];
|
|
158
|
-
addRequests: Parameters<RestrictedCrawlingContext['addRequests']>[];
|
|
159
|
-
enqueueLinks: Parameters<RestrictedCrawlingContext['enqueueLinks']>[];
|
|
160
|
-
}>;
|
|
161
|
-
/**
|
|
162
|
-
* A record of changes made to key-value stores by a request handler.
|
|
163
|
-
*/
|
|
164
|
-
get keyValueStoreChanges(): ReadonlyDeep<Record<string, Record<string, {
|
|
165
|
-
changedValue: unknown;
|
|
166
|
-
options?: RecordOptions;
|
|
167
|
-
}>>>;
|
|
168
|
-
/**
|
|
169
|
-
* Items added to datasets by a request handler.
|
|
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
185
|
/**
|
|
183
|
-
*
|
|
186
|
+
* Gives the current request `secs` more seconds to finish, for when how long it needs is only apparent
|
|
187
|
+
* once it is already running - a listing page that turns out to have far more to scroll through than
|
|
188
|
+
* usual, say. Prefer `requestHandlerTimeoutSecs`, or a per-route override via
|
|
189
|
+
* {@link Router.addHandler|`router.addHandler`}, whenever the time needed is known up front.
|
|
190
|
+
*
|
|
191
|
+
* ```ts
|
|
192
|
+
* router.addHandler('LIST', async ({ extendTimeout, page }) => {
|
|
193
|
+
* const pageCount = await countPages(page);
|
|
194
|
+
* extendTimeout(pageCount * 10);
|
|
195
|
+
* await scrapeAllPages(page);
|
|
196
|
+
* });
|
|
197
|
+
* ```
|
|
198
|
+
*
|
|
199
|
+
* Extends the request handler's own timeout and the crawler's internal one together, so the extension
|
|
200
|
+
* is not immediately undone by the latter. Calling it from a handler that has already timed out does
|
|
201
|
+
* nothing.
|
|
184
202
|
*/
|
|
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;
|
|
203
|
+
extendTimeout(secs: number): void;
|
|
197
204
|
}
|
|
198
|
-
|
|
205
|
+
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
|
*/
|
|
@@ -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 {
|
|
@@ -115,4 +113,3 @@ export class ErrorSnapshotter {
|
|
|
115
113
|
return fileName;
|
|
116
114
|
}
|
|
117
115
|
}
|
|
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