@crawlee/http 4.0.0-beta.20 → 4.0.0-beta.200
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 +14 -14
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/internals/dom-crawler.d.ts +131 -0
- package/internals/dom-crawler.js +93 -0
- package/internals/file-download.d.ts +14 -50
- package/internals/file-download.js +42 -110
- package/internals/http-crawler.d.ts +216 -204
- package/internals/http-crawler.js +257 -233
- package/internals/utils.d.ts +11 -1
- package/internals/utils.js +50 -6
- package/package.json +13 -12
- package/index.d.ts.map +0 -1
- package/index.js.map +0 -1
- package/internals/file-download.d.ts.map +0 -1
- package/internals/file-download.js.map +0 -1
- package/internals/http-crawler.d.ts.map +0 -1
- package/internals/http-crawler.js.map +0 -1
- package/internals/utils.d.ts.map +0 -1
- package/internals/utils.js.map +0 -1
|
@@ -1,25 +1,55 @@
|
|
|
1
|
-
import type { BasicCrawlerOptions, CrawlingContext, ErrorHandler, GetUserDataFromRequest,
|
|
2
|
-
import { BasicCrawler,
|
|
3
|
-
import type { LoadedRequest } from '@crawlee/core';
|
|
1
|
+
import type { BasicCrawlerOptions, ConcurrencySystem, ConcurrencySystemOptions, CrawlingContext, ErrorHandler, GetUserDataFromRequest, LoadedRequest, CrawlingRequest, RequireContextPipeline, RequestHandler, RouterHandler, RouterRoutes, RouteSchemas, RoutesFromSchemas } from '@crawlee/basic';
|
|
2
|
+
import { BasicCrawler, ContextPipeline } from '@crawlee/basic';
|
|
4
3
|
import type { Awaitable, Dictionary } from '@crawlee/types';
|
|
5
|
-
import {
|
|
6
|
-
import type { RequestLike, ResponseLike } from 'content-type';
|
|
4
|
+
import type { CheerioAPI } from 'cheerio';
|
|
7
5
|
import type { JsonValue } from 'type-fest';
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
/**
|
|
8
|
+
* A higher starting concurrency and a relaxed event loop signal, since HTTP-only crawling barely touches the event
|
|
9
|
+
* loop. {@link HttpCrawler} folds these into the {@link ConcurrencySystem} it builds by default, with your own
|
|
10
|
+
* concurrency shortcuts (`minConcurrency`, `maxConcurrency`, `maxRequestsPerMinute`) kept on top.
|
|
11
|
+
*
|
|
12
|
+
* A {@link BasicCrawlerOptions.concurrencySystem|`concurrencySystem`} you supply yourself replaces that default
|
|
13
|
+
* wholesale, tuning included, so spread these options in if you want to keep it:
|
|
14
|
+
*
|
|
15
|
+
* ```typescript
|
|
16
|
+
* new ConcurrencySystem({ ...HTTP_OPTIMIZED_CONCURRENCY_SYSTEM_OPTIONS, maxConcurrency: 50 });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare const HTTP_OPTIMIZED_CONCURRENCY_SYSTEM_OPTIONS: ConcurrencySystemOptions;
|
|
8
20
|
export type HttpErrorHandler<UserData extends Dictionary = any, // with default to Dictionary we cant use a typed router in untyped crawler
|
|
9
|
-
JSONData extends JsonValue = any
|
|
10
|
-
|
|
21
|
+
JSONData extends JsonValue = any, // with default to Dictionary we cant use a typed router in untyped crawler
|
|
22
|
+
ContextExtension = Dictionary<never>> = ErrorHandler<CrawlingContext, HttpCrawlingContext<UserData, JSONData> & ContextExtension>;
|
|
23
|
+
export interface HttpCrawlerOptions<Context extends InternalHttpCrawlingContext = InternalHttpCrawlingContext, ContextExtension = Dictionary<never>, ExtendedContext extends Context = Context & ContextExtension, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest<Context['request']>>, StatisticStateExtension extends object = {}> extends BasicCrawlerOptions<Context, ContextExtension, ExtendedContext, Routes, StatisticStateExtension> {
|
|
11
24
|
/**
|
|
12
|
-
* Timeout
|
|
25
|
+
* Timeout for the whole navigation phase, given in seconds. A single window shared by the
|
|
26
|
+
* `preNavigationHooks`, the navigation (the HTTP request to the resource), and the `postNavigationHooks` -
|
|
27
|
+
* so a slow hook eats into the same budget the navigation uses. Separate from the
|
|
28
|
+
* {@link BasicCrawlerOptions.requestHandlerTimeoutSecs|`requestHandlerTimeoutSecs`}, which times only the
|
|
29
|
+
* request handler.
|
|
13
30
|
*/
|
|
14
31
|
navigationTimeoutSecs?: number;
|
|
15
32
|
/**
|
|
16
|
-
* If set to true
|
|
33
|
+
* If set to `true`, TLS/SSL certificate errors are ignored. Forwarded to the HTTP client as
|
|
34
|
+
* {@link SendRequestOptions.ignoreTlsErrors|`ignoreTlsErrors`} on every navigation request, so custom
|
|
35
|
+
* {@link BaseHttpClient} implementations should honor that flag (the built-in impit and got-scraping
|
|
36
|
+
* clients do; the native fetch fallback cannot disable TLS verification and warns instead).
|
|
37
|
+
*
|
|
38
|
+
* @default true
|
|
17
39
|
*/
|
|
18
|
-
|
|
40
|
+
ignoreTlsErrors?: boolean;
|
|
19
41
|
/**
|
|
20
42
|
* Async functions that are sequentially evaluated before the navigation. Good for setting additional cookies
|
|
21
43
|
* or browser properties before navigation. The function accepts one parameter `crawlingContext`,
|
|
22
44
|
* which is passed to the `requestAsBrowser()` function the crawler calls to navigate.
|
|
45
|
+
*
|
|
46
|
+
* A hook may optionally return a partial object whose properties are merged into the crawling context,
|
|
47
|
+
* allowing the hook to override context members for subsequent hooks and pipeline stages.
|
|
48
|
+
*
|
|
49
|
+
* The context is built up in the following order: base context (`request`, `session`, helpers, ...) ->
|
|
50
|
+
* `extendContext` -> `preNavigationHooks` -> navigation -> `postNavigationHooks` -> `requestHandler`.
|
|
51
|
+
* This means the members added by `extendContext` are already available here, but navigation-dependent
|
|
52
|
+
* members (e.g. `response`, `body`, `$`) are not.
|
|
23
53
|
* Example:
|
|
24
54
|
* ```
|
|
25
55
|
* preNavigationHooks: [
|
|
@@ -28,27 +58,30 @@ export interface HttpCrawlerOptions<Context extends InternalHttpCrawlingContext
|
|
|
28
58
|
* },
|
|
29
59
|
* ]
|
|
30
60
|
* ```
|
|
31
|
-
*
|
|
32
|
-
* Modyfing `pageOptions` is supported only in Playwright incognito.
|
|
33
|
-
* See {@link PrePageCreateHook}
|
|
34
61
|
*/
|
|
35
|
-
preNavigationHooks?: InternalHttpHook<CrawlingContext>[];
|
|
62
|
+
preNavigationHooks?: InternalHttpHook<CrawlingContext<any>, ContextExtension>[];
|
|
36
63
|
/**
|
|
37
64
|
* Async functions that are sequentially evaluated after the navigation. Good for checking if the navigation was successful.
|
|
38
65
|
* The function accepts `crawlingContext` as the only parameter.
|
|
66
|
+
*
|
|
67
|
+
* A hook may optionally return a partial object whose properties are merged into the crawling context,
|
|
68
|
+
* which is useful for overriding the `response` after solving a challenge or re-fetching the resource.
|
|
39
69
|
* Example:
|
|
40
70
|
* ```
|
|
41
71
|
* postNavigationHooks: [
|
|
42
72
|
* async (crawlingContext) => {
|
|
43
|
-
*
|
|
73
|
+
* if (await needsRevalidation(crawlingContext)) {
|
|
74
|
+
* return { response: await refetch(crawlingContext.request) };
|
|
75
|
+
* }
|
|
44
76
|
* },
|
|
45
77
|
* ]
|
|
46
78
|
* ```
|
|
47
79
|
*/
|
|
48
|
-
postNavigationHooks?:
|
|
80
|
+
postNavigationHooks?: InternalHttpHook<CrawlingContextWithResponse, ContextExtension>[];
|
|
49
81
|
/**
|
|
50
82
|
* An array of [MIME types](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Complete_list_of_MIME_types)
|
|
51
|
-
* you want the crawler to load and process. By default, only `text/html
|
|
83
|
+
* you want the crawler to load and process. By default, only `text/html`, `application/xhtml+xml`, `text/xml`, `application/xml`,
|
|
84
|
+
* and `application/json` MIME types are supported.
|
|
52
85
|
*/
|
|
53
86
|
additionalMimeTypes?: string[];
|
|
54
87
|
/**
|
|
@@ -74,44 +107,26 @@ export interface HttpCrawlerOptions<Context extends InternalHttpCrawlingContext
|
|
|
74
107
|
*/
|
|
75
108
|
forceResponseEncoding?: string;
|
|
76
109
|
/**
|
|
77
|
-
* Automatically saves cookies to Session.
|
|
110
|
+
* Automatically saves cookies to Session. Enabled by default.
|
|
78
111
|
*
|
|
79
112
|
* It parses cookie from response "set-cookie" header saves or updates cookies for session and once the session is used for next request.
|
|
80
113
|
* It passes the "Cookie" header to the request with the session cookies.
|
|
81
114
|
*/
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* An array of HTTP response [Status Codes](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status) to be excluded from error consideration.
|
|
85
|
-
* By default, status codes >= 500 trigger errors.
|
|
86
|
-
*/
|
|
87
|
-
ignoreHttpErrorStatusCodes?: number[];
|
|
88
|
-
/**
|
|
89
|
-
* An array of additional HTTP response [Status Codes](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status) to be treated as errors.
|
|
90
|
-
* By default, status codes >= 500 trigger errors.
|
|
91
|
-
*/
|
|
92
|
-
additionalHttpErrorStatusCodes?: number[];
|
|
115
|
+
saveResponseCookies?: boolean;
|
|
93
116
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
*/
|
|
97
|
-
export type InternalHttpHook<Context> = (crawlingContext: Context) => Awaitable<void>;
|
|
98
|
-
export type HttpHook<UserData extends Dictionary = any, // with default to Dictionary we cant use a typed router in untyped crawler
|
|
99
|
-
JSONData extends JsonValue = any> = InternalHttpHook<HttpCrawlingContext<UserData, JSONData>>;
|
|
100
|
-
interface CrawlingContextWithReponse<UserData extends Dictionary = any> extends CrawlingContext<UserData> {
|
|
117
|
+
export type InternalHttpHook<Context, ContextExtension = {}> = (crawlingContext: Context & ContextExtension) => Awaitable<void | Partial<Context>>;
|
|
118
|
+
interface CrawlingContextWithResponse<UserData extends Dictionary = any> extends CrawlingContext<UserData> {
|
|
101
119
|
/**
|
|
102
120
|
* The request object that was successfully loaded and navigated to, including the {@link Request.loadedUrl|`loadedUrl`} property.
|
|
103
121
|
*/
|
|
104
|
-
request: LoadedRequest<
|
|
122
|
+
request: LoadedRequest<CrawlingRequest<UserData>>;
|
|
105
123
|
/**
|
|
106
124
|
* The HTTP response object containing status code, headers, and other response metadata.
|
|
107
125
|
*/
|
|
108
126
|
response: Response;
|
|
109
127
|
}
|
|
110
|
-
/**
|
|
111
|
-
* @internal
|
|
112
|
-
*/
|
|
113
128
|
export interface InternalHttpCrawlingContext<UserData extends Dictionary = any, // with default to Dictionary we cant use a typed router in untyped crawler
|
|
114
|
-
JSONData extends JsonValue = any> extends
|
|
129
|
+
JSONData extends JsonValue = any> extends CrawlingContextWithResponse<UserData> {
|
|
115
130
|
/**
|
|
116
131
|
* The request body of the web page.
|
|
117
132
|
* The type depends on the `Content-Type` header of the web page:
|
|
@@ -131,7 +146,11 @@ JSONData extends JsonValue = any> extends CrawlingContextWithReponse<UserData> {
|
|
|
131
146
|
encoding: BufferEncoding;
|
|
132
147
|
};
|
|
133
148
|
/**
|
|
134
|
-
* Wait for an element matching the selector to appear.
|
|
149
|
+
* Wait for an element matching the selector to appear.
|
|
150
|
+
*
|
|
151
|
+
* `HttpCrawler` and {@link CheerioCrawler} parse a response that is already fully downloaded, so there is
|
|
152
|
+
* nothing to wait for and `timeoutMs` is ignored. {@link JSDOMCrawler} and {@link LinkeDOMCrawler} poll for
|
|
153
|
+
* the selector instead, with `timeoutMs` defaulting to 5s.
|
|
135
154
|
*
|
|
136
155
|
* **Example usage:**
|
|
137
156
|
* ```ts
|
|
@@ -145,7 +164,12 @@ JSONData extends JsonValue = any> extends CrawlingContextWithReponse<UserData> {
|
|
|
145
164
|
waitForSelector(selector: string, timeoutMs?: number): Promise<void>;
|
|
146
165
|
/**
|
|
147
166
|
* Returns Cheerio handle for `page.content()`, allowing to work with the data same way as with {@link CheerioCrawler}.
|
|
148
|
-
*
|
|
167
|
+
* This is here to unify the crawler API, so they all have this handy method - in {@link CheerioCrawler} it has
|
|
168
|
+
* the same return type as the `$` context property, so use it only if you are abstracting your workflow to
|
|
169
|
+
* support different context types in one handler.
|
|
170
|
+
*
|
|
171
|
+
* When provided with the `selector` argument, it will throw if it's not available. {@link JSDOMCrawler} and
|
|
172
|
+
* {@link LinkeDOMCrawler} wait for the selector first, with `timeoutMs` defaulting to 5s.
|
|
149
173
|
*
|
|
150
174
|
* **Example usage:**
|
|
151
175
|
* ```ts
|
|
@@ -155,7 +179,7 @@ JSONData extends JsonValue = any> extends CrawlingContextWithReponse<UserData> {
|
|
|
155
179
|
* });
|
|
156
180
|
* ```
|
|
157
181
|
*/
|
|
158
|
-
parseWithCheerio(selector?: string, timeoutMs?: number): Promise<
|
|
182
|
+
parseWithCheerio(selector?: string, timeoutMs?: number): Promise<CheerioAPI>;
|
|
159
183
|
}
|
|
160
184
|
export interface HttpCrawlingContext<UserData extends Dictionary = any, JSONData extends JsonValue = any> extends InternalHttpCrawlingContext<UserData, JSONData> {
|
|
161
185
|
}
|
|
@@ -172,13 +196,15 @@ JSONData extends JsonValue = any> = RequestHandler<HttpCrawlingContext<UserData,
|
|
|
172
196
|
*
|
|
173
197
|
* This crawler downloads each URL using a plain HTTP request and doesn't do any HTML parsing.
|
|
174
198
|
*
|
|
175
|
-
* The source URLs are represented using {@link Request} objects that are fed from
|
|
176
|
-
* {@link
|
|
177
|
-
*
|
|
199
|
+
* The source URLs are represented using {@link Request} objects that are fed from the
|
|
200
|
+
* {@link IRequestManager|request manager} provided via the {@link HttpCrawlerOptions.requestManager|`requestManager`}
|
|
201
|
+
* constructor option (a {@link RequestQueue} is itself a request manager). To read from a read-only source such
|
|
202
|
+
* as a {@link RequestList} while still being able to enqueue new requests, combine it with a queue into a
|
|
203
|
+
* {@link RequestManagerTandem} via {@link IRequestLoader.toTandem|`requestLoader.toTandem()`} and pass the
|
|
204
|
+
* result as `requestManager`.
|
|
178
205
|
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
* to {@link RequestQueue} before it starts their processing. This ensures that a single URL is not crawled multiple times.
|
|
206
|
+
* > The {@link HttpCrawlerOptions.requestList|`requestList`} and {@link HttpCrawlerOptions.requestQueue|`requestQueue`}
|
|
207
|
+
* > options are deprecated; they are still accepted and folded into a single `requestManager` for back-compat.
|
|
182
208
|
*
|
|
183
209
|
* The crawler finishes when there are no more {@link Request} objects to crawl.
|
|
184
210
|
*
|
|
@@ -192,18 +218,18 @@ JSONData extends JsonValue = any> = RequestHandler<HttpCrawlingContext<UserData,
|
|
|
192
218
|
* ]
|
|
193
219
|
* ```
|
|
194
220
|
*
|
|
195
|
-
* By default, this crawler only processes web pages with the `text/html`
|
|
196
|
-
* and `application/
|
|
221
|
+
* By default, this crawler only processes web pages with the `text/html`, `application/xhtml+xml`, `text/xml`, `application/xml`,
|
|
222
|
+
* and `application/json` MIME content types (as reported by the `Content-Type` HTTP header),
|
|
197
223
|
* and skips pages with other content types. If you want the crawler to process other content types,
|
|
198
224
|
* use the {@link HttpCrawlerOptions.additionalMimeTypes} constructor option.
|
|
199
225
|
* Beware that the parsing behavior differs for HTML, XML, JSON and other types of content.
|
|
200
226
|
* For details, see {@link HttpCrawlerOptions.requestHandler}.
|
|
201
227
|
*
|
|
202
|
-
* New requests are only dispatched when there is enough free CPU and memory available,
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
* {@link
|
|
228
|
+
* New requests are only dispatched when there is enough free CPU and memory available, as judged by the crawler's
|
|
229
|
+
* {@link ConcurrencySystem}.
|
|
230
|
+
* Concurrency is tuned via the `minConcurrency`, `maxConcurrency` and `maxRequestsPerMinute` options of the
|
|
231
|
+
* constructor, or, for finer control, by injecting a pre-configured
|
|
232
|
+
* {@link ConcurrencySystem|`concurrencySystem`}.
|
|
207
233
|
*
|
|
208
234
|
* **Example usage:**
|
|
209
235
|
*
|
|
@@ -228,179 +254,165 @@ JSONData extends JsonValue = any> = RequestHandler<HttpCrawlingContext<UserData,
|
|
|
228
254
|
* ```
|
|
229
255
|
* @category Crawlers
|
|
230
256
|
*/
|
|
231
|
-
export declare class HttpCrawler<Context extends InternalHttpCrawlingContext<any, any> = InternalHttpCrawlingContext, ContextExtension = Dictionary<never>, ExtendedContext extends Context = Context & ContextExtension> extends BasicCrawler<Context, ContextExtension, ExtendedContext> {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
protected navigationTimeoutMillis: number;
|
|
237
|
-
protected ignoreSslErrors: boolean;
|
|
238
|
-
protected suggestResponseEncoding?: string;
|
|
239
|
-
protected forceResponseEncoding?: string;
|
|
240
|
-
protected additionalHttpErrorStatusCodes: Set<number>;
|
|
241
|
-
protected ignoreHttpErrorStatusCodes: Set<number>;
|
|
242
|
-
protected readonly supportedMimeTypes: Set<string>;
|
|
257
|
+
export declare class HttpCrawler<Context extends InternalHttpCrawlingContext<any, any> = InternalHttpCrawlingContext, ContextExtension = Dictionary<never>, ExtendedContext extends Context = Context & ContextExtension, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest<Context['request']>>, StatisticStateExtension extends object = {}> extends BasicCrawler<Context, ContextExtension, ExtendedContext, Routes, StatisticStateExtension> {
|
|
258
|
+
#private;
|
|
259
|
+
/**
|
|
260
|
+
* @internal
|
|
261
|
+
*/
|
|
243
262
|
protected static optionsShape: {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
299
|
-
statusMessageLoggingInterval: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
300
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
301
|
-
statusMessageCallback: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
|
|
302
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
303
|
-
retryOnBlocked: import("ow").BooleanPredicate & import("ow").BasePredicate<boolean | undefined>;
|
|
304
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
305
|
-
respectRobotsTxtFile: import("ow").AnyPredicate<boolean | object>;
|
|
306
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
307
|
-
onSkippedRequest: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
|
|
308
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
309
|
-
httpClient: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
310
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
311
|
-
minConcurrency: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
312
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
313
|
-
maxConcurrency: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
314
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
315
|
-
maxRequestsPerMinute: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
316
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
317
|
-
keepAlive: import("ow").BooleanPredicate & import("ow").BasePredicate<boolean | undefined>;
|
|
318
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
319
|
-
log: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
320
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
321
|
-
experiments: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
322
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
323
|
-
statisticsOptions: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
263
|
+
contextPipelineBuilder: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
264
|
+
extendContext: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
265
|
+
requestList: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
266
|
+
requestQueue: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
267
|
+
requestManager: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
268
|
+
requestHandler: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
269
|
+
requestHandlerTimeoutSecs: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
270
|
+
errorHandler: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
271
|
+
failedRequestHandler: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
272
|
+
maxRequestRetries: z.ZodDefault<z.ZodCustom<number, number>>;
|
|
273
|
+
sameDomainDelaySecs: z.ZodDefault<z.ZodCustom<number, number>>;
|
|
274
|
+
maxRequestsPerCrawl: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
275
|
+
maxCrawlDepth: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
276
|
+
taskLoopOptions: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
277
|
+
concurrencySystem: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
278
|
+
sessionPool: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
279
|
+
proxyConfiguration: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
280
|
+
statusMessageLoggingInterval: z.ZodDefault<z.ZodCustom<number, number>>;
|
|
281
|
+
statusMessageCallback: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
282
|
+
additionalHttpErrorStatusCodes: z.ZodDefault<z.ZodArray<z.ZodCustom<number, number>>>;
|
|
283
|
+
ignoreHttpErrorStatusCodes: z.ZodDefault<z.ZodArray<z.ZodCustom<number, number>>>;
|
|
284
|
+
blockedStatusCodes: z.ZodOptional<z.ZodArray<z.ZodCustom<number, number>>>;
|
|
285
|
+
retryOnBlocked: z.ZodDefault<z.ZodBoolean>;
|
|
286
|
+
respectRobotsTxtFile: z.ZodDefault<z.ZodUnion<readonly [z.ZodBoolean, z.ZodCustom<Dictionary, Dictionary>]>>;
|
|
287
|
+
transactionalStorage: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
|
|
288
|
+
requestQueue: z.ZodOptional<z.ZodEnum<{
|
|
289
|
+
deferred: "deferred";
|
|
290
|
+
writeThrough: "writeThrough";
|
|
291
|
+
}>>;
|
|
292
|
+
}, z.core.$strict>]>>;
|
|
293
|
+
onSkippedRequest: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
294
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
295
|
+
httpClient: z.ZodOptional<z.ZodCustom<import("@crawlee/http-client").BaseHttpClient, import("@crawlee/http-client").BaseHttpClient>>;
|
|
296
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
297
|
+
configuration: z.ZodOptional<z.ZodCustom<import("@crawlee/basic").Configuration, import("@crawlee/basic").Configuration>>;
|
|
298
|
+
storageBackend: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
299
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
300
|
+
eventManager: z.ZodOptional<z.ZodCustom<import("@crawlee/basic").EventManager, import("@crawlee/basic").EventManager>>;
|
|
301
|
+
logger: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
302
|
+
minConcurrency: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
303
|
+
maxConcurrency: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
304
|
+
initialConcurrency: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
305
|
+
maxRequestsPerMinute: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
306
|
+
keepAlive: z.ZodOptional<z.ZodBoolean>;
|
|
307
|
+
statistics: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
308
|
+
id: z.ZodOptional<z.ZodString>;
|
|
309
|
+
navigationTimeoutSecs: z.ZodDefault<z.ZodCustom<number, number>>;
|
|
310
|
+
ignoreTlsErrors: z.ZodDefault<z.ZodBoolean>;
|
|
311
|
+
additionalMimeTypes: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
312
|
+
suggestResponseEncoding: z.ZodOptional<z.ZodString>;
|
|
313
|
+
forceResponseEncoding: z.ZodOptional<z.ZodString>;
|
|
314
|
+
saveResponseCookies: z.ZodDefault<z.ZodBoolean>;
|
|
315
|
+
preNavigationHooks: z.ZodDefault<z.ZodCustom<unknown[], unknown[]>>;
|
|
316
|
+
postNavigationHooks: z.ZodDefault<z.ZodCustom<unknown[], unknown[]>>;
|
|
324
317
|
};
|
|
318
|
+
/** @internal */
|
|
319
|
+
protected static optionsSchema: z.ZodObject<{
|
|
320
|
+
contextPipelineBuilder: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
321
|
+
extendContext: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
322
|
+
requestList: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
323
|
+
requestQueue: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
324
|
+
requestManager: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
325
|
+
requestHandler: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
326
|
+
requestHandlerTimeoutSecs: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
327
|
+
errorHandler: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
328
|
+
failedRequestHandler: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
329
|
+
maxRequestRetries: z.ZodDefault<z.ZodCustom<number, number>>;
|
|
330
|
+
sameDomainDelaySecs: z.ZodDefault<z.ZodCustom<number, number>>;
|
|
331
|
+
maxRequestsPerCrawl: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
332
|
+
maxCrawlDepth: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
333
|
+
taskLoopOptions: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
334
|
+
concurrencySystem: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
335
|
+
sessionPool: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
336
|
+
proxyConfiguration: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
337
|
+
statusMessageLoggingInterval: z.ZodDefault<z.ZodCustom<number, number>>;
|
|
338
|
+
statusMessageCallback: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
339
|
+
additionalHttpErrorStatusCodes: z.ZodDefault<z.ZodArray<z.ZodCustom<number, number>>>;
|
|
340
|
+
ignoreHttpErrorStatusCodes: z.ZodDefault<z.ZodArray<z.ZodCustom<number, number>>>;
|
|
341
|
+
blockedStatusCodes: z.ZodOptional<z.ZodArray<z.ZodCustom<number, number>>>;
|
|
342
|
+
retryOnBlocked: z.ZodDefault<z.ZodBoolean>;
|
|
343
|
+
respectRobotsTxtFile: z.ZodDefault<z.ZodUnion<readonly [z.ZodBoolean, z.ZodCustom<Dictionary, Dictionary>]>>;
|
|
344
|
+
transactionalStorage: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
|
|
345
|
+
requestQueue: z.ZodOptional<z.ZodEnum<{
|
|
346
|
+
deferred: "deferred";
|
|
347
|
+
writeThrough: "writeThrough";
|
|
348
|
+
}>>;
|
|
349
|
+
}, z.core.$strict>]>>;
|
|
350
|
+
onSkippedRequest: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
351
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
352
|
+
httpClient: z.ZodOptional<z.ZodCustom<import("@crawlee/http-client").BaseHttpClient, import("@crawlee/http-client").BaseHttpClient>>;
|
|
353
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
354
|
+
configuration: z.ZodOptional<z.ZodCustom<import("@crawlee/basic").Configuration, import("@crawlee/basic").Configuration>>;
|
|
355
|
+
storageBackend: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
356
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
357
|
+
eventManager: z.ZodOptional<z.ZodCustom<import("@crawlee/basic").EventManager, import("@crawlee/basic").EventManager>>;
|
|
358
|
+
logger: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
359
|
+
minConcurrency: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
360
|
+
maxConcurrency: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
361
|
+
initialConcurrency: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
362
|
+
maxRequestsPerMinute: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
363
|
+
keepAlive: z.ZodOptional<z.ZodBoolean>;
|
|
364
|
+
statistics: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
365
|
+
id: z.ZodOptional<z.ZodString>;
|
|
366
|
+
navigationTimeoutSecs: z.ZodDefault<z.ZodCustom<number, number>>;
|
|
367
|
+
ignoreTlsErrors: z.ZodDefault<z.ZodBoolean>;
|
|
368
|
+
additionalMimeTypes: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
369
|
+
suggestResponseEncoding: z.ZodOptional<z.ZodString>;
|
|
370
|
+
forceResponseEncoding: z.ZodOptional<z.ZodString>;
|
|
371
|
+
saveResponseCookies: z.ZodDefault<z.ZodBoolean>;
|
|
372
|
+
preNavigationHooks: z.ZodDefault<z.ZodCustom<unknown[], unknown[]>>;
|
|
373
|
+
postNavigationHooks: z.ZodDefault<z.ZodCustom<unknown[], unknown[]>>;
|
|
374
|
+
}, z.core.$strict>;
|
|
325
375
|
/**
|
|
326
376
|
* All `HttpCrawlerOptions` parameters are passed via an options object.
|
|
327
377
|
*/
|
|
328
|
-
constructor(options?: HttpCrawlerOptions<Context, ContextExtension, ExtendedContext> & RequireContextPipeline<InternalHttpCrawlingContext, Context
|
|
378
|
+
constructor(options?: HttpCrawlerOptions<Context, ContextExtension, ExtendedContext, Routes, StatisticStateExtension> & RequireContextPipeline<InternalHttpCrawlingContext, Context>);
|
|
379
|
+
/** @internal */
|
|
380
|
+
protected getNavigationTimeoutMillis(): number;
|
|
381
|
+
/** @internal */
|
|
382
|
+
protected createDefaultConcurrencySystem(options: ConcurrencySystemOptions): ConcurrencySystem;
|
|
329
383
|
protected buildContextPipeline(): ContextPipeline<CrawlingContext, InternalHttpCrawlingContext>;
|
|
384
|
+
private prepareHttpRequest;
|
|
330
385
|
private makeHttpRequest;
|
|
331
386
|
private processHttpResponse;
|
|
332
387
|
private handleBlockedRequestByContent;
|
|
333
|
-
protected isRequestBlocked(crawlingContext: InternalHttpCrawlingContext): Promise<string | false>;
|
|
334
|
-
/**
|
|
335
|
-
* Returns the `Cookie` header value based on the current context and
|
|
336
|
-
* any changes that occurred in the navigation hooks.
|
|
337
|
-
*/
|
|
338
|
-
protected _applyCookies({ session, request }: CrawlingContext, preHookCookies: string, postHookCookies: string): string;
|
|
339
388
|
/**
|
|
340
389
|
* Function to make the HTTP request. It performs optimizations
|
|
341
390
|
* on the request such as only downloading the request body if the
|
|
342
391
|
* received content type matches text/html, application/xml, application/xhtml+xml.
|
|
343
392
|
*/
|
|
344
|
-
|
|
393
|
+
private requestFunction;
|
|
345
394
|
/**
|
|
346
395
|
* Encodes and parses response according to the provided content type
|
|
347
396
|
*/
|
|
348
|
-
|
|
349
|
-
response: Response;
|
|
350
|
-
contentType: {
|
|
351
|
-
type: string;
|
|
352
|
-
encoding: BufferEncoding;
|
|
353
|
-
};
|
|
354
|
-
body: string;
|
|
355
|
-
} | {
|
|
356
|
-
body: Buffer<ArrayBuffer>;
|
|
357
|
-
response: Response;
|
|
358
|
-
contentType: {
|
|
359
|
-
type: string;
|
|
360
|
-
encoding: BufferEncoding;
|
|
361
|
-
};
|
|
362
|
-
}>;
|
|
397
|
+
private parseResponse;
|
|
363
398
|
/**
|
|
364
399
|
* Combines the provided `requestOptions` with mandatory (non-overridable) values.
|
|
365
400
|
*/
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
369
|
-
method: import("@crawlee/types").AllowedHttpMethods;
|
|
370
|
-
proxyUrl: string | undefined;
|
|
371
|
-
timeout: number;
|
|
372
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
373
|
-
cookieJar: import("tough-cookie").CookieJar | undefined;
|
|
374
|
-
sessionToken: Session | undefined;
|
|
375
|
-
headers: Record<string, string> | undefined;
|
|
376
|
-
https: {
|
|
377
|
-
rejectUnauthorized: boolean;
|
|
378
|
-
};
|
|
379
|
-
body: string | undefined;
|
|
380
|
-
};
|
|
381
|
-
protected _encodeResponse(request: CrawleeRequest, response: Response, encoding: BufferEncoding): {
|
|
382
|
-
encoding: BufferEncoding;
|
|
383
|
-
response: Response;
|
|
384
|
-
};
|
|
401
|
+
private getRequestOptions;
|
|
402
|
+
private encodeResponse;
|
|
385
403
|
/**
|
|
386
404
|
* Checks and extends supported mime types
|
|
387
405
|
*/
|
|
388
|
-
|
|
406
|
+
private extendSupportedMimeTypes;
|
|
389
407
|
/**
|
|
390
408
|
* Handles timeout request
|
|
391
409
|
*/
|
|
392
|
-
|
|
393
|
-
private
|
|
410
|
+
private handleRequestTimeout;
|
|
411
|
+
private abortDownloadOfBody;
|
|
394
412
|
/**
|
|
395
413
|
* @internal wraps public utility for mocking purposes
|
|
396
414
|
*/
|
|
397
|
-
private
|
|
398
|
-
}
|
|
399
|
-
interface RequestFunctionOptions {
|
|
400
|
-
request: CrawleeRequest;
|
|
401
|
-
session?: Session;
|
|
402
|
-
proxyUrl?: string;
|
|
403
|
-
cookieString?: string;
|
|
415
|
+
private requestAsBrowser;
|
|
404
416
|
}
|
|
405
417
|
/**
|
|
406
418
|
* Creates new {@link Router} instance that works based on request labels.
|
|
@@ -426,7 +438,7 @@ interface RequestFunctionOptions {
|
|
|
426
438
|
* await crawler.run();
|
|
427
439
|
* ```
|
|
428
440
|
*/
|
|
429
|
-
|
|
430
|
-
export declare function createHttpRouter<Context extends HttpCrawlingContext = HttpCrawlingContext, UserData extends Dictionary = GetUserDataFromRequest<Context['request']>>(routes?: RouterRoutes<Context, UserData
|
|
441
|
+
export declare function createHttpRouter<Context extends HttpCrawlingContext = HttpCrawlingContext, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest<Context['request']>>>(routes?: RouterRoutes<Context, Routes>): RouterHandler<Context, Routes>;
|
|
442
|
+
export declare function createHttpRouter<Context extends HttpCrawlingContext = HttpCrawlingContext, UserData extends Dictionary = GetUserDataFromRequest<Context['request']>>(routes?: RouterRoutes<Context, Record<string, UserData>>): RouterHandler<Context, Record<string, UserData>>;
|
|
443
|
+
export declare function createHttpRouter<Context extends HttpCrawlingContext = HttpCrawlingContext, const Schemas extends RouteSchemas = RouteSchemas>(schemas: Schemas): RouterHandler<Context, RoutesFromSchemas<Schemas>>;
|
|
431
444
|
export {};
|
|
432
|
-
//# sourceMappingURL=http-crawler.d.ts.map
|