@crawlee/http 4.0.0-beta.16 → 4.0.0-beta.161
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 +0 -1
- package/index.js +0 -1
- package/internals/file-download.d.ts +13 -11
- package/internals/file-download.js +47 -43
- package/internals/http-crawler.d.ts +212 -270
- package/internals/http-crawler.js +259 -248
- 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
|
@@ -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 {
|
|
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 { CheerioAPI } from 'cheerio';
|
|
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:
|
|
@@ -166,7 +172,7 @@ JSONData extends JsonValue = any> extends CrawlingContextWithReponse<UserData> {
|
|
|
166
172
|
* });
|
|
167
173
|
* ```
|
|
168
174
|
*/
|
|
169
|
-
parseWithCheerio(selector?: string, timeoutMs?: number): Promise<
|
|
175
|
+
parseWithCheerio(selector?: string, timeoutMs?: number): Promise<CheerioAPI>;
|
|
170
176
|
}
|
|
171
177
|
export interface HttpCrawlingContext<UserData extends Dictionary = any, JSONData extends JsonValue = any> extends InternalHttpCrawlingContext<UserData, JSONData> {
|
|
172
178
|
}
|
|
@@ -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,236 +247,170 @@ 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 = Dictionary<never>, ExtendedContext extends Context = Context & ContextExtension> extends BasicCrawler<Context, ContextExtension, ExtendedContext> {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
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;
|
|
252
|
+
/**
|
|
253
|
+
* @internal
|
|
254
|
+
*/
|
|
254
255
|
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
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
310
|
-
statusMessageLoggingInterval: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
311
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
312
|
-
statusMessageCallback: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
|
|
313
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
314
|
-
retryOnBlocked: import("ow").BooleanPredicate & import("ow").BasePredicate<boolean | undefined>;
|
|
315
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
316
|
-
respectRobotsTxtFile: import("ow").AnyPredicate<boolean | object>;
|
|
317
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
318
|
-
onSkippedRequest: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
|
|
319
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
320
|
-
httpClient: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
321
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
322
|
-
minConcurrency: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
323
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
324
|
-
maxConcurrency: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
325
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
326
|
-
maxRequestsPerMinute: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
327
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
328
|
-
keepAlive: import("ow").BooleanPredicate & import("ow").BasePredicate<boolean | undefined>;
|
|
329
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
330
|
-
log: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
331
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
332
|
-
experiments: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
333
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
334
|
-
statisticsOptions: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
256
|
+
contextPipelineBuilder: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
257
|
+
extendContext: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
258
|
+
requestList: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
259
|
+
requestQueue: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
260
|
+
requestManager: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
261
|
+
requestHandler: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
262
|
+
requestHandlerTimeoutSecs: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
263
|
+
errorHandler: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
264
|
+
failedRequestHandler: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
265
|
+
maxRequestRetries: z.ZodDefault<z.ZodCustom<number, number>>;
|
|
266
|
+
sameDomainDelaySecs: z.ZodDefault<z.ZodCustom<number, number>>;
|
|
267
|
+
maxRequestsPerCrawl: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
268
|
+
maxCrawlDepth: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
269
|
+
taskLoopOptions: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
270
|
+
concurrencySystem: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
271
|
+
sessionPool: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
272
|
+
proxyConfiguration: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
273
|
+
statusMessageLoggingInterval: z.ZodDefault<z.ZodCustom<number, number>>;
|
|
274
|
+
statusMessageCallback: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
275
|
+
additionalHttpErrorStatusCodes: z.ZodDefault<z.ZodArray<z.ZodCustom<number, number>>>;
|
|
276
|
+
ignoreHttpErrorStatusCodes: z.ZodDefault<z.ZodArray<z.ZodCustom<number, number>>>;
|
|
277
|
+
blockedStatusCodes: z.ZodOptional<z.ZodArray<z.ZodCustom<number, number>>>;
|
|
278
|
+
retryOnBlocked: z.ZodDefault<z.ZodBoolean>;
|
|
279
|
+
respectRobotsTxtFile: z.ZodDefault<z.ZodUnion<readonly [z.ZodBoolean, z.ZodCustom<Dictionary, Dictionary>]>>;
|
|
280
|
+
transactionalStorage: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
|
|
281
|
+
requestQueue: z.ZodOptional<z.ZodEnum<{
|
|
282
|
+
deferred: "deferred";
|
|
283
|
+
writeThrough: "writeThrough";
|
|
284
|
+
}>>;
|
|
285
|
+
}, z.core.$strict>]>>;
|
|
286
|
+
onSkippedRequest: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
287
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
288
|
+
httpClient: z.ZodOptional<z.ZodCustom<import("@crawlee/http-client").BaseHttpClient, import("@crawlee/http-client").BaseHttpClient>>;
|
|
289
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
290
|
+
configuration: z.ZodOptional<z.ZodCustom<import("@crawlee/basic").Configuration, import("@crawlee/basic").Configuration>>;
|
|
291
|
+
storageBackend: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
292
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
293
|
+
eventManager: z.ZodOptional<z.ZodCustom<import("@crawlee/basic").EventManager, import("@crawlee/basic").EventManager>>;
|
|
294
|
+
logger: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
295
|
+
minConcurrency: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
296
|
+
maxConcurrency: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
297
|
+
initialConcurrency: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
298
|
+
maxRequestsPerMinute: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
299
|
+
keepAlive: z.ZodOptional<z.ZodBoolean>;
|
|
300
|
+
statistics: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
301
|
+
id: z.ZodOptional<z.ZodString>;
|
|
302
|
+
navigationTimeoutSecs: z.ZodDefault<z.ZodCustom<number, number>>;
|
|
303
|
+
ignoreTlsErrors: z.ZodDefault<z.ZodBoolean>;
|
|
304
|
+
additionalMimeTypes: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
305
|
+
suggestResponseEncoding: z.ZodOptional<z.ZodString>;
|
|
306
|
+
forceResponseEncoding: z.ZodOptional<z.ZodString>;
|
|
307
|
+
saveResponseCookies: z.ZodDefault<z.ZodBoolean>;
|
|
308
|
+
preNavigationHooks: z.ZodDefault<z.ZodCustom<unknown[], unknown[]>>;
|
|
309
|
+
postNavigationHooks: z.ZodDefault<z.ZodCustom<unknown[], unknown[]>>;
|
|
335
310
|
};
|
|
311
|
+
/** @internal */
|
|
312
|
+
protected static optionsSchema: z.ZodObject<{
|
|
313
|
+
contextPipelineBuilder: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
314
|
+
extendContext: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
315
|
+
requestList: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
316
|
+
requestQueue: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
317
|
+
requestManager: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
318
|
+
requestHandler: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
319
|
+
requestHandlerTimeoutSecs: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
320
|
+
errorHandler: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
321
|
+
failedRequestHandler: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
322
|
+
maxRequestRetries: z.ZodDefault<z.ZodCustom<number, number>>;
|
|
323
|
+
sameDomainDelaySecs: z.ZodDefault<z.ZodCustom<number, number>>;
|
|
324
|
+
maxRequestsPerCrawl: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
325
|
+
maxCrawlDepth: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
326
|
+
taskLoopOptions: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
327
|
+
concurrencySystem: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
328
|
+
sessionPool: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
329
|
+
proxyConfiguration: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
330
|
+
statusMessageLoggingInterval: z.ZodDefault<z.ZodCustom<number, number>>;
|
|
331
|
+
statusMessageCallback: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
332
|
+
additionalHttpErrorStatusCodes: z.ZodDefault<z.ZodArray<z.ZodCustom<number, number>>>;
|
|
333
|
+
ignoreHttpErrorStatusCodes: z.ZodDefault<z.ZodArray<z.ZodCustom<number, number>>>;
|
|
334
|
+
blockedStatusCodes: z.ZodOptional<z.ZodArray<z.ZodCustom<number, number>>>;
|
|
335
|
+
retryOnBlocked: z.ZodDefault<z.ZodBoolean>;
|
|
336
|
+
respectRobotsTxtFile: z.ZodDefault<z.ZodUnion<readonly [z.ZodBoolean, z.ZodCustom<Dictionary, Dictionary>]>>;
|
|
337
|
+
transactionalStorage: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
|
|
338
|
+
requestQueue: z.ZodOptional<z.ZodEnum<{
|
|
339
|
+
deferred: "deferred";
|
|
340
|
+
writeThrough: "writeThrough";
|
|
341
|
+
}>>;
|
|
342
|
+
}, z.core.$strict>]>>;
|
|
343
|
+
onSkippedRequest: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
344
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
345
|
+
httpClient: z.ZodOptional<z.ZodCustom<import("@crawlee/http-client").BaseHttpClient, import("@crawlee/http-client").BaseHttpClient>>;
|
|
346
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
347
|
+
configuration: z.ZodOptional<z.ZodCustom<import("@crawlee/basic").Configuration, import("@crawlee/basic").Configuration>>;
|
|
348
|
+
storageBackend: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
349
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
350
|
+
eventManager: z.ZodOptional<z.ZodCustom<import("@crawlee/basic").EventManager, import("@crawlee/basic").EventManager>>;
|
|
351
|
+
logger: z.ZodOptional<z.ZodType<Dictionary<any>, unknown, z.core.$ZodTypeInternals<Dictionary<any>, unknown>>>;
|
|
352
|
+
minConcurrency: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
353
|
+
maxConcurrency: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
354
|
+
initialConcurrency: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
355
|
+
maxRequestsPerMinute: z.ZodOptional<z.ZodCustom<number, number>>;
|
|
356
|
+
keepAlive: z.ZodOptional<z.ZodBoolean>;
|
|
357
|
+
statistics: z.ZodOptional<z.ZodCustom<Dictionary, Dictionary>>;
|
|
358
|
+
id: z.ZodOptional<z.ZodString>;
|
|
359
|
+
navigationTimeoutSecs: z.ZodDefault<z.ZodCustom<number, number>>;
|
|
360
|
+
ignoreTlsErrors: z.ZodDefault<z.ZodBoolean>;
|
|
361
|
+
additionalMimeTypes: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
362
|
+
suggestResponseEncoding: z.ZodOptional<z.ZodString>;
|
|
363
|
+
forceResponseEncoding: z.ZodOptional<z.ZodString>;
|
|
364
|
+
saveResponseCookies: z.ZodDefault<z.ZodBoolean>;
|
|
365
|
+
preNavigationHooks: z.ZodDefault<z.ZodCustom<unknown[], unknown[]>>;
|
|
366
|
+
postNavigationHooks: z.ZodDefault<z.ZodCustom<unknown[], unknown[]>>;
|
|
367
|
+
}, z.core.$strict>;
|
|
336
368
|
/**
|
|
337
369
|
* All `HttpCrawlerOptions` parameters are passed via an options object.
|
|
338
370
|
*/
|
|
339
|
-
constructor(options?: HttpCrawlerOptions<Context, ContextExtension, ExtendedContext> & RequireContextPipeline<InternalHttpCrawlingContext, Context
|
|
371
|
+
constructor(options?: HttpCrawlerOptions<Context, ContextExtension, ExtendedContext, Routes, StatisticStateExtension> & RequireContextPipeline<InternalHttpCrawlingContext, Context>);
|
|
372
|
+
protected getNavigationTimeoutMillis(): number;
|
|
373
|
+
/**
|
|
374
|
+
* Folds {@link HTTP_OPTIMIZED_CONCURRENCY_SYSTEM_OPTIONS} into the default system, keeping the user's
|
|
375
|
+
* concurrency shortcuts on top. Not called for a supplied
|
|
376
|
+
* {@link BasicCrawlerOptions.concurrencySystem|`concurrencySystem`} — spread the constant into it yourself to
|
|
377
|
+
* keep the tuning.
|
|
378
|
+
*/
|
|
379
|
+
protected createDefaultConcurrencySystem(options: ConcurrencySystemOptions): ConcurrencySystem;
|
|
340
380
|
protected buildContextPipeline(): ContextPipeline<CrawlingContext, InternalHttpCrawlingContext>;
|
|
381
|
+
private prepareHttpRequest;
|
|
341
382
|
private makeHttpRequest;
|
|
342
383
|
private processHttpResponse;
|
|
343
384
|
private handleBlockedRequestByContent;
|
|
344
385
|
protected isRequestBlocked(crawlingContext: InternalHttpCrawlingContext): Promise<string | false>;
|
|
345
|
-
/**
|
|
346
|
-
* Sets the cookie header to `gotOptions` based on the provided request and session headers, as well as any changes that occurred due to hooks.
|
|
347
|
-
*/
|
|
348
|
-
protected _applyCookies({ session, request }: CrawlingContext, gotOptions: OptionsInit, preHookCookies: string, postHookCookies: string): void;
|
|
349
386
|
/**
|
|
350
387
|
* Function to make the HTTP request. It performs optimizations
|
|
351
388
|
* on the request such as only downloading the request body if the
|
|
352
389
|
* received content type matches text/html, application/xml, application/xhtml+xml.
|
|
353
390
|
*/
|
|
354
|
-
|
|
391
|
+
private requestFunction;
|
|
355
392
|
/**
|
|
356
393
|
* Encodes and parses response according to the provided content type
|
|
357
394
|
*/
|
|
358
|
-
|
|
359
|
-
response: Response;
|
|
360
|
-
contentType: {
|
|
361
|
-
type: string;
|
|
362
|
-
encoding: BufferEncoding;
|
|
363
|
-
};
|
|
364
|
-
body: string;
|
|
365
|
-
} | {
|
|
366
|
-
body: Buffer<ArrayBuffer>;
|
|
367
|
-
response: Response;
|
|
368
|
-
contentType: {
|
|
369
|
-
type: string;
|
|
370
|
-
encoding: BufferEncoding;
|
|
371
|
-
};
|
|
372
|
-
}>;
|
|
395
|
+
private parseResponse;
|
|
373
396
|
/**
|
|
374
397
|
* Combines the provided `requestOptions` with mandatory (non-overridable) values.
|
|
375
398
|
*/
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
379
|
-
headers?: import("got-scraping").Headers | undefined;
|
|
380
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
381
|
-
body?: string | Buffer | Readable | Generator | AsyncGenerator | import("form-data-encoder").FormDataLike | undefined;
|
|
382
|
-
json?: unknown;
|
|
383
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
384
|
-
request?: import("got-scraping").RequestFunction | undefined;
|
|
385
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
386
|
-
agent?: import("got-scraping").Agents | undefined;
|
|
387
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
388
|
-
h2session?: import("http2").ClientHttp2Session | undefined;
|
|
389
|
-
decompress?: boolean | undefined;
|
|
390
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
391
|
-
timeout?: import("got-scraping").Delays | undefined;
|
|
392
|
-
prefixUrl?: string | URL | undefined;
|
|
393
|
-
form?: Record<string, any> | undefined;
|
|
394
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
395
|
-
cookieJar?: import("got-scraping").PromiseCookieJar | import("got-scraping").ToughCookieJar | undefined;
|
|
396
|
-
signal?: AbortSignal | undefined;
|
|
397
|
-
ignoreInvalidCookies?: boolean | undefined;
|
|
398
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
399
|
-
searchParams?: string | import("got-scraping").SearchParameters | URLSearchParams | undefined;
|
|
400
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
401
|
-
dnsLookup?: import("cacheable-lookup").default["lookup"] | undefined;
|
|
402
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
403
|
-
dnsCache?: import("cacheable-lookup").default | boolean | undefined;
|
|
404
|
-
context?: Record<string, unknown> | undefined;
|
|
405
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
406
|
-
followRedirect?: boolean | ((response: import("got-scraping").PlainResponse) => boolean) | undefined;
|
|
407
|
-
maxRedirects?: number | undefined;
|
|
408
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
409
|
-
cache?: string | import("cacheable-request").StorageAdapter | boolean | undefined;
|
|
410
|
-
throwHttpErrors?: boolean | undefined;
|
|
411
|
-
username?: string | undefined;
|
|
412
|
-
password?: string | undefined;
|
|
413
|
-
http2?: boolean | undefined;
|
|
414
|
-
allowGetBody?: boolean | undefined;
|
|
415
|
-
methodRewriting?: boolean | undefined;
|
|
416
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
417
|
-
dnsLookupIpVersion?: import("got-scraping").DnsLookupIpVersion;
|
|
418
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
419
|
-
parseJson?: import("got-scraping").ParseJsonFunction | undefined;
|
|
420
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
421
|
-
stringifyJson?: import("got-scraping").StringifyJsonFunction | undefined;
|
|
422
|
-
localAddress?: string | undefined;
|
|
423
|
-
method?: Method | undefined;
|
|
424
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
425
|
-
createConnection?: import("got-scraping").CreateConnectionFunction | undefined;
|
|
426
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
427
|
-
cacheOptions?: import("got-scraping").CacheOptions | undefined;
|
|
428
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
429
|
-
https?: import("got-scraping").HttpsOptions | undefined;
|
|
430
|
-
encoding?: BufferEncoding | undefined;
|
|
431
|
-
resolveBodyOnly?: boolean | undefined;
|
|
432
|
-
isStream?: boolean | undefined;
|
|
433
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
434
|
-
responseType?: import("got-scraping").ResponseType | undefined;
|
|
435
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
436
|
-
pagination?: import("got-scraping").PaginationOptions<unknown, unknown> | undefined;
|
|
437
|
-
setHost?: boolean | undefined;
|
|
438
|
-
maxHeaderSize?: number | undefined;
|
|
439
|
-
enableUnixSockets?: boolean | undefined;
|
|
440
|
-
} & {
|
|
441
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
442
|
-
hooks?: Partial<import("got-scraping").Hooks>;
|
|
443
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
444
|
-
retry?: Partial<import("got-scraping").RetryOptions>;
|
|
445
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
446
|
-
} & import("got-scraping").Context & Required<Pick<OptionsInit, "url">> & {
|
|
447
|
-
isStream: true;
|
|
448
|
-
};
|
|
449
|
-
protected _encodeResponse(request: Request, response: Response, encoding: BufferEncoding): {
|
|
450
|
-
encoding: BufferEncoding;
|
|
451
|
-
response: Response;
|
|
452
|
-
};
|
|
399
|
+
private getRequestOptions;
|
|
400
|
+
private encodeResponse;
|
|
453
401
|
/**
|
|
454
402
|
* Checks and extends supported mime types
|
|
455
403
|
*/
|
|
456
|
-
|
|
404
|
+
private extendSupportedMimeTypes;
|
|
457
405
|
/**
|
|
458
406
|
* Handles timeout request
|
|
459
407
|
*/
|
|
460
|
-
|
|
461
|
-
private
|
|
408
|
+
private handleRequestTimeout;
|
|
409
|
+
private abortDownloadOfBody;
|
|
462
410
|
/**
|
|
463
411
|
* @internal wraps public utility for mocking purposes
|
|
464
412
|
*/
|
|
465
|
-
private
|
|
466
|
-
}
|
|
467
|
-
interface RequestFunctionOptions {
|
|
468
|
-
request: Request;
|
|
469
|
-
session?: Session;
|
|
470
|
-
proxyUrl?: string;
|
|
471
|
-
gotOptions: OptionsInit;
|
|
413
|
+
private requestAsBrowser;
|
|
472
414
|
}
|
|
473
415
|
/**
|
|
474
416
|
* Creates new {@link Router} instance that works based on request labels.
|
|
@@ -494,7 +436,7 @@ interface RequestFunctionOptions {
|
|
|
494
436
|
* await crawler.run();
|
|
495
437
|
* ```
|
|
496
438
|
*/
|
|
497
|
-
|
|
498
|
-
export declare function createHttpRouter<Context extends HttpCrawlingContext = HttpCrawlingContext, UserData extends Dictionary = GetUserDataFromRequest<Context['request']>>(routes?: RouterRoutes<Context, UserData
|
|
439
|
+
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>;
|
|
440
|
+
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>>;
|
|
441
|
+
export declare function createHttpRouter<Context extends HttpCrawlingContext = HttpCrawlingContext, const Schemas extends RouteSchemas = RouteSchemas>(schemas: Schemas): RouterHandler<Context, RoutesFromSchemas<Schemas>>;
|
|
499
442
|
export {};
|
|
500
|
-
//# sourceMappingURL=http-crawler.d.ts.map
|