@crawlee/http 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/index.d.ts +0 -1
- package/index.js +0 -1
- package/internals/file-download.d.ts +47 -8
- package/internals/file-download.js +106 -19
- package/internals/http-crawler.d.ts +205 -267
- package/internals/http-crawler.js +257 -240
- package/internals/utils.d.ts +11 -1
- package/internals/utils.js +50 -6
- package/package.json +12 -11
- 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
- package/tsconfig.build.tsbuildinfo +0 -1
|
@@ -1,65 +1,87 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import { BasicCrawler, Configuration, ContextPipeline } from '@crawlee/basic';
|
|
5
|
-
import type { HttpResponse, LoadedRequest } from '@crawlee/core';
|
|
1
|
+
import type { BasicCrawlerOptions, ConcurrencySystem, ConcurrencySystemOptions, CrawlingContext, ErrorHandler, GetUserDataFromRequest, Request as CrawleeRequest, RequestHandler, RequireContextPipeline, RouterHandler, RouterRoutes, RouteSchemas, RoutesFromSchemas } from '@crawlee/basic';
|
|
2
|
+
import { BasicCrawler, ContextPipeline } from '@crawlee/basic';
|
|
3
|
+
import { type LoadedRequest } from '@crawlee/core';
|
|
6
4
|
import type { Awaitable, Dictionary } from '@crawlee/types';
|
|
7
|
-
import { type CheerioRoot } from '@crawlee/utils';
|
|
8
|
-
import type { RequestLike, ResponseLike } from 'content-type';
|
|
9
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
10
|
-
import type { Method, OptionsInit } from 'got-scraping';
|
|
5
|
+
import { type CheerioRoot } from '@crawlee/utils/internal';
|
|
11
6
|
import type { JsonValue } from 'type-fest';
|
|
7
|
+
import { z } from 'zod';
|
|
12
8
|
/**
|
|
13
|
-
*
|
|
14
|
-
* @
|
|
9
|
+
* A higher starting concurrency and a relaxed event loop signal, since HTTP-only crawling barely touches the event
|
|
10
|
+
* loop. {@link HttpCrawler} folds these into the {@link ConcurrencySystem} it builds by default.
|
|
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
|
+
* ```
|
|
15
18
|
*/
|
|
16
|
-
export
|
|
17
|
-
body?: unknown;
|
|
18
|
-
};
|
|
19
|
+
export declare const HTTP_OPTIMIZED_CONCURRENCY_SYSTEM_OPTIONS: ConcurrencySystemOptions;
|
|
19
20
|
export type HttpErrorHandler<UserData extends Dictionary = any, // with default to Dictionary we cant use a typed router in untyped crawler
|
|
20
|
-
JSONData extends JsonValue = any
|
|
21
|
-
|
|
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> {
|
|
22
24
|
/**
|
|
23
|
-
* 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.
|
|
24
30
|
*/
|
|
25
31
|
navigationTimeoutSecs?: number;
|
|
26
32
|
/**
|
|
27
|
-
* 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
|
|
28
39
|
*/
|
|
29
|
-
|
|
40
|
+
ignoreTlsErrors?: boolean;
|
|
30
41
|
/**
|
|
31
42
|
* Async functions that are sequentially evaluated before the navigation. Good for setting additional cookies
|
|
32
|
-
* or browser properties before navigation. The function accepts
|
|
33
|
-
* which
|
|
43
|
+
* or browser properties before navigation. The function accepts one parameter `crawlingContext`,
|
|
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.
|
|
34
53
|
* Example:
|
|
35
54
|
* ```
|
|
36
55
|
* preNavigationHooks: [
|
|
37
|
-
* async (crawlingContext
|
|
56
|
+
* async (crawlingContext) => {
|
|
38
57
|
* // ...
|
|
39
58
|
* },
|
|
40
59
|
* ]
|
|
41
60
|
* ```
|
|
42
|
-
*
|
|
43
|
-
* Modyfing `pageOptions` is supported only in Playwright incognito.
|
|
44
|
-
* See {@link PrePageCreateHook}
|
|
45
61
|
*/
|
|
46
|
-
preNavigationHooks?: InternalHttpHook<CrawlingContext>[];
|
|
62
|
+
preNavigationHooks?: InternalHttpHook<CrawlingContext<any>, ContextExtension>[];
|
|
47
63
|
/**
|
|
48
64
|
* Async functions that are sequentially evaluated after the navigation. Good for checking if the navigation was successful.
|
|
49
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.
|
|
50
69
|
* Example:
|
|
51
70
|
* ```
|
|
52
71
|
* postNavigationHooks: [
|
|
53
72
|
* async (crawlingContext) => {
|
|
54
|
-
*
|
|
73
|
+
* if (await needsRevalidation(crawlingContext)) {
|
|
74
|
+
* return { response: await refetch(crawlingContext.request) };
|
|
75
|
+
* }
|
|
55
76
|
* },
|
|
56
77
|
* ]
|
|
57
78
|
* ```
|
|
58
79
|
*/
|
|
59
|
-
postNavigationHooks?: ((crawlingContext:
|
|
80
|
+
postNavigationHooks?: ((crawlingContext: CrawlingContextWithResponse & ContextExtension) => Awaitable<void | Partial<CrawlingContextWithResponse>>)[];
|
|
60
81
|
/**
|
|
61
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)
|
|
62
|
-
* 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.
|
|
63
85
|
*/
|
|
64
86
|
additionalMimeTypes?: string[];
|
|
65
87
|
/**
|
|
@@ -85,44 +107,28 @@ export interface HttpCrawlerOptions<Context extends InternalHttpCrawlingContext
|
|
|
85
107
|
*/
|
|
86
108
|
forceResponseEncoding?: string;
|
|
87
109
|
/**
|
|
88
|
-
* Automatically saves cookies to Session.
|
|
110
|
+
* Automatically saves cookies to Session. Enabled by default.
|
|
89
111
|
*
|
|
90
112
|
* It parses cookie from response "set-cookie" header saves or updates cookies for session and once the session is used for next request.
|
|
91
113
|
* It passes the "Cookie" header to the request with the session cookies.
|
|
92
114
|
*/
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* An array of HTTP response [Status Codes](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status) to be excluded from error consideration.
|
|
96
|
-
* By default, status codes >= 500 trigger errors.
|
|
97
|
-
*/
|
|
98
|
-
ignoreHttpErrorStatusCodes?: number[];
|
|
99
|
-
/**
|
|
100
|
-
* An array of additional HTTP response [Status Codes](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status) to be treated as errors.
|
|
101
|
-
* By default, status codes >= 500 trigger errors.
|
|
102
|
-
*/
|
|
103
|
-
additionalHttpErrorStatusCodes?: number[];
|
|
115
|
+
saveResponseCookies?: boolean;
|
|
104
116
|
}
|
|
105
|
-
|
|
106
|
-
* @internal
|
|
107
|
-
*/
|
|
108
|
-
export type InternalHttpHook<Context> = (crawlingContext: Context, gotOptions: OptionsInit) => Awaitable<void>;
|
|
117
|
+
export type InternalHttpHook<Context, ContextExtension = {}> = (crawlingContext: Context & ContextExtension) => Awaitable<void | Partial<Context>>;
|
|
109
118
|
export type HttpHook<UserData extends Dictionary = any, // with default to Dictionary we cant use a typed router in untyped crawler
|
|
110
119
|
JSONData extends JsonValue = any> = InternalHttpHook<HttpCrawlingContext<UserData, JSONData>>;
|
|
111
|
-
interface
|
|
120
|
+
interface CrawlingContextWithResponse<UserData extends Dictionary = any> extends CrawlingContext<UserData> {
|
|
112
121
|
/**
|
|
113
122
|
* The request object that was successfully loaded and navigated to, including the {@link Request.loadedUrl|`loadedUrl`} property.
|
|
114
123
|
*/
|
|
115
|
-
request: LoadedRequest<
|
|
124
|
+
request: LoadedRequest<CrawleeRequest<UserData>>;
|
|
116
125
|
/**
|
|
117
126
|
* The HTTP response object containing status code, headers, and other response metadata.
|
|
118
127
|
*/
|
|
119
128
|
response: Response;
|
|
120
129
|
}
|
|
121
|
-
/**
|
|
122
|
-
* @internal
|
|
123
|
-
*/
|
|
124
130
|
export interface InternalHttpCrawlingContext<UserData extends Dictionary = any, // with default to Dictionary we cant use a typed router in untyped crawler
|
|
125
|
-
JSONData extends JsonValue = any> extends
|
|
131
|
+
JSONData extends JsonValue = any> extends CrawlingContextWithResponse<UserData> {
|
|
126
132
|
/**
|
|
127
133
|
* The request body of the web page.
|
|
128
134
|
* The type depends on the `Content-Type` header of the web page:
|
|
@@ -183,38 +189,40 @@ JSONData extends JsonValue = any> = RequestHandler<HttpCrawlingContext<UserData,
|
|
|
183
189
|
*
|
|
184
190
|
* This crawler downloads each URL using a plain HTTP request and doesn't do any HTML parsing.
|
|
185
191
|
*
|
|
186
|
-
* The source URLs are represented using {@link Request} objects that are fed from
|
|
187
|
-
* {@link
|
|
188
|
-
*
|
|
192
|
+
* The source URLs are represented using {@link Request} objects that are fed from the
|
|
193
|
+
* {@link IRequestManager|request manager} provided via the {@link HttpCrawlerOptions.requestManager|`requestManager`}
|
|
194
|
+
* constructor option (a {@link RequestQueue} is itself a request manager). To read from a read-only source such
|
|
195
|
+
* as a {@link RequestList} while still being able to enqueue new requests, combine it with a queue into a
|
|
196
|
+
* {@link RequestManagerTandem} via {@link IRequestLoader.toTandem|`requestLoader.toTandem()`} and pass the
|
|
197
|
+
* result as `requestManager`.
|
|
189
198
|
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
* to {@link RequestQueue} before it starts their processing. This ensures that a single URL is not crawled multiple times.
|
|
199
|
+
* > The {@link HttpCrawlerOptions.requestList|`requestList`} and {@link HttpCrawlerOptions.requestQueue|`requestQueue`}
|
|
200
|
+
* > options are deprecated; they are still accepted and folded into a single `requestManager` for back-compat.
|
|
193
201
|
*
|
|
194
202
|
* The crawler finishes when there are no more {@link Request} objects to crawl.
|
|
195
203
|
*
|
|
196
|
-
* We can use the `preNavigationHooks` to adjust
|
|
204
|
+
* We can use the `preNavigationHooks` to adjust the crawling context before the request is made:
|
|
197
205
|
*
|
|
198
206
|
* ```javascript
|
|
199
207
|
* preNavigationHooks: [
|
|
200
|
-
* (crawlingContext
|
|
208
|
+
* (crawlingContext) => {
|
|
201
209
|
* // ...
|
|
202
210
|
* },
|
|
203
211
|
* ]
|
|
204
212
|
* ```
|
|
205
213
|
*
|
|
206
|
-
* By default, this crawler only processes web pages with the `text/html`
|
|
207
|
-
* and `application/
|
|
214
|
+
* By default, this crawler only processes web pages with the `text/html`, `application/xhtml+xml`, `text/xml`, `application/xml`,
|
|
215
|
+
* and `application/json` MIME content types (as reported by the `Content-Type` HTTP header),
|
|
208
216
|
* and skips pages with other content types. If you want the crawler to process other content types,
|
|
209
217
|
* use the {@link HttpCrawlerOptions.additionalMimeTypes} constructor option.
|
|
210
218
|
* Beware that the parsing behavior differs for HTML, XML, JSON and other types of content.
|
|
211
219
|
* For details, see {@link HttpCrawlerOptions.requestHandler}.
|
|
212
220
|
*
|
|
213
|
-
* New requests are only dispatched when there is enough free CPU and memory available,
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
* {@link
|
|
221
|
+
* New requests are only dispatched when there is enough free CPU and memory available, as judged by the crawler's
|
|
222
|
+
* {@link ConcurrencySystem}.
|
|
223
|
+
* Concurrency is tuned via the `minConcurrency`, `maxConcurrency` and `maxRequestsPerMinute` options of the
|
|
224
|
+
* constructor, or, for finer control, by injecting a pre-configured
|
|
225
|
+
* {@link ConcurrencySystem|`concurrencySystem`}.
|
|
218
226
|
*
|
|
219
227
|
* **Example usage:**
|
|
220
228
|
*
|
|
@@ -239,234 +247,164 @@ JSONData extends JsonValue = any> = RequestHandler<HttpCrawlingContext<UserData,
|
|
|
239
247
|
* ```
|
|
240
248
|
* @category Crawlers
|
|
241
249
|
*/
|
|
242
|
-
export declare class HttpCrawler<Context extends InternalHttpCrawlingContext<any, any> = InternalHttpCrawlingContext, ContextExtension =
|
|
243
|
-
|
|
244
|
-
protected preNavigationHooks: InternalHttpHook<CrawlingContext>[];
|
|
245
|
-
protected postNavigationHooks: ((crawlingContext: CrawlingContextWithReponse) => Awaitable<void>)[];
|
|
246
|
-
protected persistCookiesPerSession: boolean;
|
|
247
|
-
protected navigationTimeoutMillis: number;
|
|
248
|
-
protected ignoreSslErrors: boolean;
|
|
249
|
-
protected suggestResponseEncoding?: string;
|
|
250
|
-
protected forceResponseEncoding?: string;
|
|
251
|
-
protected additionalHttpErrorStatusCodes: Set<number>;
|
|
252
|
-
protected ignoreHttpErrorStatusCodes: Set<number>;
|
|
253
|
-
protected readonly supportedMimeTypes: Set<string>;
|
|
250
|
+
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> {
|
|
251
|
+
#private;
|
|
254
252
|
protected static optionsShape: {
|
|
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
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
statusMessageLoggingInterval: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
309
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
310
|
-
statusMessageCallback: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
|
|
311
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
312
|
-
retryOnBlocked: import("ow").BooleanPredicate & import("ow").BasePredicate<boolean | undefined>;
|
|
313
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
314
|
-
respectRobotsTxtFile: import("ow").BooleanPredicate & import("ow").BasePredicate<boolean | undefined>;
|
|
315
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
316
|
-
onSkippedRequest: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
|
|
317
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
318
|
-
httpClient: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
319
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
320
|
-
minConcurrency: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
321
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
322
|
-
maxConcurrency: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
323
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
324
|
-
maxRequestsPerMinute: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
325
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
326
|
-
keepAlive: import("ow").BooleanPredicate & import("ow").BasePredicate<boolean | undefined>;
|
|
327
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
328
|
-
log: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
329
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
330
|
-
experiments: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
331
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
332
|
-
statisticsOptions: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
253
|
+
navigationTimeoutSecs: z.ZodDefault<z.ZodCustom<number, number>>;
|
|
254
|
+
ignoreTlsErrors: z.ZodDefault<z.ZodBoolean>;
|
|
255
|
+
additionalMimeTypes: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
256
|
+
suggestResponseEncoding: z.ZodOptional<z.ZodString>;
|
|
257
|
+
forceResponseEncoding: z.ZodOptional<z.ZodString>;
|
|
258
|
+
saveResponseCookies: z.ZodDefault<z.ZodBoolean>;
|
|
259
|
+
preNavigationHooks: z.ZodDefault<z.ZodCustom<unknown[], unknown[]>>;
|
|
260
|
+
postNavigationHooks: z.ZodDefault<z.ZodCustom<unknown[], unknown[]>>;
|
|
261
|
+
contextPipelineBuilder: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
262
|
+
extendContext: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
263
|
+
requestList: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
264
|
+
requestQueue: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
265
|
+
requestManager: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
266
|
+
requestHandler: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
267
|
+
requestHandlerTimeoutSecs: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
268
|
+
errorHandler: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
269
|
+
failedRequestHandler: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
270
|
+
maxRequestRetries: z.ZodDefault<z.ZodCustom<number, number>>;
|
|
271
|
+
sameDomainDelaySecs: z.ZodDefault<z.ZodCustom<number, number>>;
|
|
272
|
+
maxRequestsPerCrawl: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
273
|
+
maxCrawlDepth: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
274
|
+
taskLoopOptions: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
275
|
+
concurrencySystem: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
276
|
+
sessionPool: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
277
|
+
proxyConfiguration: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
278
|
+
statusMessageLoggingInterval: z.ZodDefault<z.ZodCustom<number, number>>;
|
|
279
|
+
statusMessageCallback: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
280
|
+
additionalHttpErrorStatusCodes: z.ZodDefault<z.ZodArray<z.ZodCustom<number, number>>>;
|
|
281
|
+
ignoreHttpErrorStatusCodes: z.ZodDefault<z.ZodArray<z.ZodCustom<number, number>>>;
|
|
282
|
+
blockedStatusCodes: z.ZodOptional<z.ZodArray<z.ZodCustom<number, number>>>;
|
|
283
|
+
retryOnBlocked: z.ZodDefault<z.ZodBoolean>;
|
|
284
|
+
respectRobotsTxtFile: z.ZodDefault<z.ZodUnion<readonly [z.ZodBoolean, z.ZodCustom<Dictionary, Dictionary>]>>;
|
|
285
|
+
transactionalStorage: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
|
|
286
|
+
requestQueue: z.ZodOptional<z.ZodEnum<{
|
|
287
|
+
deferred: "deferred";
|
|
288
|
+
writeThrough: "writeThrough";
|
|
289
|
+
}>>;
|
|
290
|
+
}, z.core.$strict>]>>;
|
|
291
|
+
onSkippedRequest: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
292
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
293
|
+
httpClient: z.ZodOptional<z.ZodCustom<import("@crawlee/http-client").BaseHttpClient, import("@crawlee/http-client").BaseHttpClient>>;
|
|
294
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
295
|
+
configuration: z.ZodOptional<z.ZodCustom<import("@crawlee/basic").Configuration, import("@crawlee/basic").Configuration>>;
|
|
296
|
+
storageBackend: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
297
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
298
|
+
eventManager: z.ZodOptional<z.ZodCustom<import("@crawlee/basic").EventManager, import("@crawlee/basic").EventManager>>;
|
|
299
|
+
logger: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
300
|
+
minConcurrency: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
301
|
+
maxConcurrency: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
302
|
+
maxRequestsPerMinute: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
303
|
+
keepAlive: z.ZodOptional<z.ZodBoolean>;
|
|
304
|
+
statistics: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
305
|
+
id: z.ZodOptional<z.ZodString>;
|
|
333
306
|
};
|
|
307
|
+
protected static optionsSchema: z.ZodObject<{
|
|
308
|
+
navigationTimeoutSecs: z.ZodDefault<z.ZodCustom<number, number>>;
|
|
309
|
+
ignoreTlsErrors: z.ZodDefault<z.ZodBoolean>;
|
|
310
|
+
additionalMimeTypes: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
311
|
+
suggestResponseEncoding: z.ZodOptional<z.ZodString>;
|
|
312
|
+
forceResponseEncoding: z.ZodOptional<z.ZodString>;
|
|
313
|
+
saveResponseCookies: z.ZodDefault<z.ZodBoolean>;
|
|
314
|
+
preNavigationHooks: z.ZodDefault<z.ZodCustom<unknown[], unknown[]>>;
|
|
315
|
+
postNavigationHooks: z.ZodDefault<z.ZodCustom<unknown[], unknown[]>>;
|
|
316
|
+
contextPipelineBuilder: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
317
|
+
extendContext: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
318
|
+
requestList: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
319
|
+
requestQueue: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
320
|
+
requestManager: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
321
|
+
requestHandler: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
322
|
+
requestHandlerTimeoutSecs: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
323
|
+
errorHandler: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
324
|
+
failedRequestHandler: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
325
|
+
maxRequestRetries: z.ZodDefault<z.ZodCustom<number, number>>;
|
|
326
|
+
sameDomainDelaySecs: z.ZodDefault<z.ZodCustom<number, number>>;
|
|
327
|
+
maxRequestsPerCrawl: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
328
|
+
maxCrawlDepth: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
329
|
+
taskLoopOptions: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
330
|
+
concurrencySystem: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
331
|
+
sessionPool: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
332
|
+
proxyConfiguration: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
333
|
+
statusMessageLoggingInterval: z.ZodDefault<z.ZodCustom<number, number>>;
|
|
334
|
+
statusMessageCallback: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
335
|
+
additionalHttpErrorStatusCodes: z.ZodDefault<z.ZodArray<z.ZodCustom<number, number>>>;
|
|
336
|
+
ignoreHttpErrorStatusCodes: z.ZodDefault<z.ZodArray<z.ZodCustom<number, number>>>;
|
|
337
|
+
blockedStatusCodes: z.ZodOptional<z.ZodArray<z.ZodCustom<number, number>>>;
|
|
338
|
+
retryOnBlocked: z.ZodDefault<z.ZodBoolean>;
|
|
339
|
+
respectRobotsTxtFile: z.ZodDefault<z.ZodUnion<readonly [z.ZodBoolean, z.ZodCustom<Dictionary, Dictionary>]>>;
|
|
340
|
+
transactionalStorage: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
|
|
341
|
+
requestQueue: z.ZodOptional<z.ZodEnum<{
|
|
342
|
+
deferred: "deferred";
|
|
343
|
+
writeThrough: "writeThrough";
|
|
344
|
+
}>>;
|
|
345
|
+
}, z.core.$strict>]>>;
|
|
346
|
+
onSkippedRequest: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
347
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
348
|
+
httpClient: z.ZodOptional<z.ZodCustom<import("@crawlee/http-client").BaseHttpClient, import("@crawlee/http-client").BaseHttpClient>>;
|
|
349
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
350
|
+
configuration: z.ZodOptional<z.ZodCustom<import("@crawlee/basic").Configuration, import("@crawlee/basic").Configuration>>;
|
|
351
|
+
storageBackend: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
352
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
353
|
+
eventManager: z.ZodOptional<z.ZodCustom<import("@crawlee/basic").EventManager, import("@crawlee/basic").EventManager>>;
|
|
354
|
+
logger: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
355
|
+
minConcurrency: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
356
|
+
maxConcurrency: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
357
|
+
maxRequestsPerMinute: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
358
|
+
keepAlive: z.ZodOptional<z.ZodBoolean>;
|
|
359
|
+
statistics: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
360
|
+
id: z.ZodOptional<z.ZodString>;
|
|
361
|
+
}, z.core.$strict>;
|
|
334
362
|
/**
|
|
335
363
|
* All `HttpCrawlerOptions` parameters are passed via an options object.
|
|
336
364
|
*/
|
|
337
|
-
constructor(options?: HttpCrawlerOptions<Context, ExtendedContext> & RequireContextPipeline<InternalHttpCrawlingContext, Context
|
|
365
|
+
constructor(options?: HttpCrawlerOptions<Context, ContextExtension, ExtendedContext, Routes, StatisticStateExtension> & RequireContextPipeline<InternalHttpCrawlingContext, Context>);
|
|
366
|
+
protected getNavigationTimeoutMillis(): number;
|
|
367
|
+
/**
|
|
368
|
+
* Folds {@link HTTP_OPTIMIZED_CONCURRENCY_SYSTEM_OPTIONS} into the default system, keeping the user's
|
|
369
|
+
* concurrency shortcuts on top. Not called for a supplied
|
|
370
|
+
* {@link BasicCrawlerOptions.concurrencySystem|`concurrencySystem`} — spread the constant into it yourself to
|
|
371
|
+
* keep the tuning.
|
|
372
|
+
*/
|
|
373
|
+
protected createDefaultConcurrencySystem(options: ConcurrencySystemOptions): ConcurrencySystem;
|
|
338
374
|
protected buildContextPipeline(): ContextPipeline<CrawlingContext, InternalHttpCrawlingContext>;
|
|
375
|
+
private prepareHttpRequest;
|
|
339
376
|
private makeHttpRequest;
|
|
340
377
|
private processHttpResponse;
|
|
341
378
|
private handleBlockedRequestByContent;
|
|
342
379
|
protected isRequestBlocked(crawlingContext: InternalHttpCrawlingContext): Promise<string | false>;
|
|
343
|
-
/**
|
|
344
|
-
* Sets the cookie header to `gotOptions` based on the provided request and session headers, as well as any changes that occurred due to hooks.
|
|
345
|
-
*/
|
|
346
|
-
protected _applyCookies({ session, request }: CrawlingContext, gotOptions: OptionsInit, preHookCookies: string, postHookCookies: string): void;
|
|
347
380
|
/**
|
|
348
381
|
* Function to make the HTTP request. It performs optimizations
|
|
349
382
|
* on the request such as only downloading the request body if the
|
|
350
383
|
* received content type matches text/html, application/xml, application/xhtml+xml.
|
|
351
384
|
*/
|
|
352
|
-
|
|
385
|
+
private requestFunction;
|
|
353
386
|
/**
|
|
354
387
|
* Encodes and parses response according to the provided content type
|
|
355
388
|
*/
|
|
356
|
-
|
|
357
|
-
response: Response;
|
|
358
|
-
contentType: {
|
|
359
|
-
type: string;
|
|
360
|
-
encoding: BufferEncoding;
|
|
361
|
-
};
|
|
362
|
-
body: string;
|
|
363
|
-
} | {
|
|
364
|
-
body: Buffer<ArrayBuffer>;
|
|
365
|
-
response: Response;
|
|
366
|
-
contentType: {
|
|
367
|
-
type: string;
|
|
368
|
-
encoding: BufferEncoding;
|
|
369
|
-
};
|
|
370
|
-
}>;
|
|
389
|
+
private parseResponse;
|
|
371
390
|
/**
|
|
372
391
|
* Combines the provided `requestOptions` with mandatory (non-overridable) values.
|
|
373
392
|
*/
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
377
|
-
headers?: import("got-scraping").Headers | undefined;
|
|
378
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
379
|
-
body?: string | Buffer | Readable | Generator | AsyncGenerator | import("form-data-encoder").FormDataLike | undefined;
|
|
380
|
-
json?: unknown;
|
|
381
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
382
|
-
request?: import("got-scraping").RequestFunction | undefined;
|
|
383
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
384
|
-
agent?: import("got-scraping").Agents | undefined;
|
|
385
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
386
|
-
h2session?: import("http2").ClientHttp2Session | undefined;
|
|
387
|
-
decompress?: boolean | undefined;
|
|
388
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
389
|
-
timeout?: import("got-scraping").Delays | undefined;
|
|
390
|
-
prefixUrl?: string | URL | undefined;
|
|
391
|
-
form?: Record<string, any> | undefined;
|
|
392
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
393
|
-
cookieJar?: import("got-scraping").PromiseCookieJar | import("got-scraping").ToughCookieJar | undefined;
|
|
394
|
-
signal?: AbortSignal | undefined;
|
|
395
|
-
ignoreInvalidCookies?: boolean | undefined;
|
|
396
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
397
|
-
searchParams?: string | import("got-scraping").SearchParameters | URLSearchParams | undefined;
|
|
398
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
399
|
-
dnsLookup?: import("cacheable-lookup").default["lookup"] | undefined;
|
|
400
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
401
|
-
dnsCache?: import("cacheable-lookup").default | boolean | undefined;
|
|
402
|
-
context?: Record<string, unknown> | undefined;
|
|
403
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
404
|
-
followRedirect?: boolean | ((response: import("got-scraping").PlainResponse) => boolean) | undefined;
|
|
405
|
-
maxRedirects?: number | undefined;
|
|
406
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
407
|
-
cache?: string | import("cacheable-request").StorageAdapter | boolean | undefined;
|
|
408
|
-
throwHttpErrors?: boolean | undefined;
|
|
409
|
-
username?: string | undefined;
|
|
410
|
-
password?: string | undefined;
|
|
411
|
-
http2?: boolean | undefined;
|
|
412
|
-
allowGetBody?: boolean | undefined;
|
|
413
|
-
methodRewriting?: boolean | undefined;
|
|
414
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
415
|
-
dnsLookupIpVersion?: import("got-scraping").DnsLookupIpVersion;
|
|
416
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
417
|
-
parseJson?: import("got-scraping").ParseJsonFunction | undefined;
|
|
418
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
419
|
-
stringifyJson?: import("got-scraping").StringifyJsonFunction | undefined;
|
|
420
|
-
localAddress?: string | undefined;
|
|
421
|
-
method?: Method | undefined;
|
|
422
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
423
|
-
createConnection?: import("got-scraping").CreateConnectionFunction | undefined;
|
|
424
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
425
|
-
cacheOptions?: import("got-scraping").CacheOptions | undefined;
|
|
426
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
427
|
-
https?: import("got-scraping").HttpsOptions | undefined;
|
|
428
|
-
encoding?: BufferEncoding | undefined;
|
|
429
|
-
resolveBodyOnly?: boolean | undefined;
|
|
430
|
-
isStream?: boolean | undefined;
|
|
431
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
432
|
-
responseType?: import("got-scraping").ResponseType | undefined;
|
|
433
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
434
|
-
pagination?: import("got-scraping").PaginationOptions<unknown, unknown> | undefined;
|
|
435
|
-
setHost?: boolean | undefined;
|
|
436
|
-
maxHeaderSize?: number | undefined;
|
|
437
|
-
enableUnixSockets?: boolean | undefined;
|
|
438
|
-
} & {
|
|
439
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
440
|
-
hooks?: Partial<import("got-scraping").Hooks>;
|
|
441
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
442
|
-
retry?: Partial<import("got-scraping").RetryOptions>;
|
|
443
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
444
|
-
} & import("got-scraping").Context & Required<Pick<OptionsInit, "url">> & {
|
|
445
|
-
isStream: true;
|
|
446
|
-
};
|
|
447
|
-
protected _encodeResponse(request: Request, response: Response, encoding: BufferEncoding): {
|
|
448
|
-
encoding: BufferEncoding;
|
|
449
|
-
response: Response;
|
|
450
|
-
};
|
|
393
|
+
private getRequestOptions;
|
|
394
|
+
private encodeResponse;
|
|
451
395
|
/**
|
|
452
396
|
* Checks and extends supported mime types
|
|
453
397
|
*/
|
|
454
|
-
|
|
398
|
+
private extendSupportedMimeTypes;
|
|
455
399
|
/**
|
|
456
400
|
* Handles timeout request
|
|
457
401
|
*/
|
|
458
|
-
|
|
459
|
-
private
|
|
402
|
+
private handleRequestTimeout;
|
|
403
|
+
private abortDownloadOfBody;
|
|
460
404
|
/**
|
|
461
405
|
* @internal wraps public utility for mocking purposes
|
|
462
406
|
*/
|
|
463
|
-
private
|
|
464
|
-
}
|
|
465
|
-
interface RequestFunctionOptions {
|
|
466
|
-
request: Request;
|
|
467
|
-
session?: Session;
|
|
468
|
-
proxyUrl?: string;
|
|
469
|
-
gotOptions: OptionsInit;
|
|
407
|
+
private requestAsBrowser;
|
|
470
408
|
}
|
|
471
409
|
/**
|
|
472
410
|
* Creates new {@link Router} instance that works based on request labels.
|
|
@@ -492,7 +430,7 @@ interface RequestFunctionOptions {
|
|
|
492
430
|
* await crawler.run();
|
|
493
431
|
* ```
|
|
494
432
|
*/
|
|
495
|
-
|
|
496
|
-
export declare function createHttpRouter<Context extends HttpCrawlingContext = HttpCrawlingContext, UserData extends Dictionary = GetUserDataFromRequest<Context['request']>>(routes?: RouterRoutes<Context, UserData
|
|
433
|
+
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>;
|
|
434
|
+
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>>;
|
|
435
|
+
export declare function createHttpRouter<Context extends HttpCrawlingContext = HttpCrawlingContext, const Schemas extends RouteSchemas = RouteSchemas>(schemas: Schemas): RouterHandler<Context, RoutesFromSchemas<Schemas>>;
|
|
497
436
|
export {};
|
|
498
|
-
//# sourceMappingURL=http-crawler.d.ts.map
|