@crawlee/http 4.0.0-beta.99 → 4.0.0-rc.1
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 +1 -1
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/internals/dom-crawler.d.ts +131 -0
- package/internals/dom-crawler.js +93 -0
- package/internals/file-download.d.ts +11 -61
- package/internals/file-download.js +19 -117
- package/internals/http-crawler.d.ts +147 -149
- package/internals/http-crawler.js +137 -133
- package/internals/utils.js +10 -14
- package/package.json +11 -14
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import type { BasicCrawlerOptions, ConcurrencySystem, ConcurrencySystemOptions, CrawlingContext, ErrorHandler, GetUserDataFromRequest,
|
|
1
|
+
import type { BasicCrawlerOptions, ConcurrencySystem, ConcurrencySystemOptions, CrawlingContext, ErrorHandler, GetUserDataFromRequest, LoadedRequest, CrawlingRequest, RequireContextPipeline, RequestHandler, RouterHandler, RouterRoutes, RouteSchemas, RoutesFromSchemas } from '@crawlee/basic';
|
|
2
2
|
import { BasicCrawler, ContextPipeline } from '@crawlee/basic';
|
|
3
|
-
import { type LoadedRequest } from '@crawlee/core';
|
|
4
3
|
import type { Awaitable, Dictionary } from '@crawlee/types';
|
|
5
|
-
import {
|
|
4
|
+
import type { CheerioAPI } from 'cheerio';
|
|
6
5
|
import type { JsonValue } from 'type-fest';
|
|
6
|
+
import { z } from 'zod';
|
|
7
7
|
/**
|
|
8
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
|
|
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.
|
|
10
11
|
*
|
|
11
12
|
* A {@link BasicCrawlerOptions.concurrencySystem|`concurrencySystem`} you supply yourself replaces that default
|
|
12
13
|
* wholesale, tuning included, so spread these options in if you want to keep it:
|
|
@@ -19,7 +20,7 @@ export declare const HTTP_OPTIMIZED_CONCURRENCY_SYSTEM_OPTIONS: ConcurrencySyste
|
|
|
19
20
|
export type HttpErrorHandler<UserData extends Dictionary = any, // with default to Dictionary we cant use a typed router in untyped crawler
|
|
20
21
|
JSONData extends JsonValue = any, // with default to Dictionary we cant use a typed router in untyped crawler
|
|
21
22
|
ContextExtension = Dictionary<never>> = ErrorHandler<CrawlingContext, HttpCrawlingContext<UserData, JSONData> & ContextExtension>;
|
|
22
|
-
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']
|
|
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> {
|
|
23
24
|
/**
|
|
24
25
|
* Timeout for the whole navigation phase, given in seconds. A single window shared by the
|
|
25
26
|
* `preNavigationHooks`, the navigation (the HTTP request to the resource), and the `postNavigationHooks` -
|
|
@@ -29,9 +30,14 @@ export interface HttpCrawlerOptions<Context extends InternalHttpCrawlingContext
|
|
|
29
30
|
*/
|
|
30
31
|
navigationTimeoutSecs?: number;
|
|
31
32
|
/**
|
|
32
|
-
* 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
|
|
33
39
|
*/
|
|
34
|
-
|
|
40
|
+
ignoreTlsErrors?: boolean;
|
|
35
41
|
/**
|
|
36
42
|
* Async functions that are sequentially evaluated before the navigation. Good for setting additional cookies
|
|
37
43
|
* or browser properties before navigation. The function accepts one parameter `crawlingContext`,
|
|
@@ -53,7 +59,7 @@ export interface HttpCrawlerOptions<Context extends InternalHttpCrawlingContext
|
|
|
53
59
|
* ]
|
|
54
60
|
* ```
|
|
55
61
|
*/
|
|
56
|
-
preNavigationHooks?: InternalHttpHook<CrawlingContext
|
|
62
|
+
preNavigationHooks?: InternalHttpHook<CrawlingContext<any>, ContextExtension>[];
|
|
57
63
|
/**
|
|
58
64
|
* Async functions that are sequentially evaluated after the navigation. Good for checking if the navigation was successful.
|
|
59
65
|
* The function accepts `crawlingContext` as the only parameter.
|
|
@@ -71,7 +77,7 @@ export interface HttpCrawlerOptions<Context extends InternalHttpCrawlingContext
|
|
|
71
77
|
* ]
|
|
72
78
|
* ```
|
|
73
79
|
*/
|
|
74
|
-
postNavigationHooks?:
|
|
80
|
+
postNavigationHooks?: InternalHttpHook<CrawlingContextWithResponse, ContextExtension>[];
|
|
75
81
|
/**
|
|
76
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)
|
|
77
83
|
* you want the crawler to load and process. By default, only `text/html`, `application/xhtml+xml`, `text/xml`, `application/xml`,
|
|
@@ -109,13 +115,11 @@ export interface HttpCrawlerOptions<Context extends InternalHttpCrawlingContext
|
|
|
109
115
|
saveResponseCookies?: boolean;
|
|
110
116
|
}
|
|
111
117
|
export type InternalHttpHook<Context, ContextExtension = {}> = (crawlingContext: Context & ContextExtension) => Awaitable<void | Partial<Context>>;
|
|
112
|
-
export type HttpHook<UserData extends Dictionary = any, // with default to Dictionary we cant use a typed router in untyped crawler
|
|
113
|
-
JSONData extends JsonValue = any> = InternalHttpHook<HttpCrawlingContext<UserData, JSONData>>;
|
|
114
118
|
interface CrawlingContextWithResponse<UserData extends Dictionary = any> extends CrawlingContext<UserData> {
|
|
115
119
|
/**
|
|
116
120
|
* The request object that was successfully loaded and navigated to, including the {@link Request.loadedUrl|`loadedUrl`} property.
|
|
117
121
|
*/
|
|
118
|
-
request: LoadedRequest<
|
|
122
|
+
request: LoadedRequest<CrawlingRequest<UserData>>;
|
|
119
123
|
/**
|
|
120
124
|
* The HTTP response object containing status code, headers, and other response metadata.
|
|
121
125
|
*/
|
|
@@ -142,7 +146,11 @@ JSONData extends JsonValue = any> extends CrawlingContextWithResponse<UserData>
|
|
|
142
146
|
encoding: BufferEncoding;
|
|
143
147
|
};
|
|
144
148
|
/**
|
|
145
|
-
* 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.
|
|
146
154
|
*
|
|
147
155
|
* **Example usage:**
|
|
148
156
|
* ```ts
|
|
@@ -156,7 +164,12 @@ JSONData extends JsonValue = any> extends CrawlingContextWithResponse<UserData>
|
|
|
156
164
|
waitForSelector(selector: string, timeoutMs?: number): Promise<void>;
|
|
157
165
|
/**
|
|
158
166
|
* Returns Cheerio handle for `page.content()`, allowing to work with the data same way as with {@link CheerioCrawler}.
|
|
159
|
-
*
|
|
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.
|
|
160
173
|
*
|
|
161
174
|
* **Example usage:**
|
|
162
175
|
* ```ts
|
|
@@ -166,7 +179,7 @@ JSONData extends JsonValue = any> extends CrawlingContextWithResponse<UserData>
|
|
|
166
179
|
* });
|
|
167
180
|
* ```
|
|
168
181
|
*/
|
|
169
|
-
parseWithCheerio(selector?: string, timeoutMs?: number): Promise<
|
|
182
|
+
parseWithCheerio(selector?: string, timeoutMs?: number): Promise<CheerioAPI>;
|
|
170
183
|
}
|
|
171
184
|
export interface HttpCrawlingContext<UserData extends Dictionary = any, JSONData extends JsonValue = any> extends InternalHttpCrawlingContext<UserData, JSONData> {
|
|
172
185
|
}
|
|
@@ -241,149 +254,134 @@ JSONData extends JsonValue = any> = RequestHandler<HttpCrawlingContext<UserData,
|
|
|
241
254
|
* ```
|
|
242
255
|
* @category Crawlers
|
|
243
256
|
*/
|
|
244
|
-
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']
|
|
245
|
-
private
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
private ignoreSslErrors;
|
|
250
|
-
private suggestResponseEncoding?;
|
|
251
|
-
private forceResponseEncoding?;
|
|
252
|
-
private readonly supportedMimeTypes;
|
|
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
|
+
*/
|
|
253
262
|
protected static optionsShape: {
|
|
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
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
309
|
-
ignoreHttpErrorStatusCodes: import("ow").ArrayPredicate<number>;
|
|
310
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
311
|
-
blockedStatusCodes: import("ow").ArrayPredicate<number>;
|
|
312
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
313
|
-
retryOnBlocked: import("ow").BooleanPredicate & import("ow").BasePredicate<boolean | undefined>;
|
|
314
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
315
|
-
respectRobotsTxtFile: import("ow").AnyPredicate<boolean | object>;
|
|
316
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
317
|
-
onSkippedRequest: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
|
|
318
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
319
|
-
httpClient: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
320
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
321
|
-
configuration: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
322
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
323
|
-
storageBackend: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
324
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
325
|
-
eventManager: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
326
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
327
|
-
logger: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
328
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
329
|
-
minConcurrency: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
330
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
331
|
-
maxConcurrency: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
332
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
333
|
-
maxRequestsPerMinute: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
334
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
335
|
-
keepAlive: import("ow").BooleanPredicate & import("ow").BasePredicate<boolean | undefined>;
|
|
336
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
337
|
-
statisticsOptions: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
338
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
339
|
-
id: import("ow").StringPredicate & import("ow").BasePredicate<string | 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.ZodInstanceOf<import("@crawlee/http-client").BaseHttpClient>>;
|
|
296
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
297
|
+
configuration: z.ZodOptional<z.ZodInstanceOf<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.ZodInstanceOf<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[]>>;
|
|
340
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.ZodInstanceOf<import("@crawlee/http-client").BaseHttpClient>>;
|
|
353
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
354
|
+
configuration: z.ZodOptional<z.ZodInstanceOf<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.ZodInstanceOf<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>;
|
|
341
375
|
/**
|
|
342
376
|
* All `HttpCrawlerOptions` parameters are passed via an options object.
|
|
343
377
|
*/
|
|
344
|
-
constructor(options?: HttpCrawlerOptions<Context, ContextExtension, ExtendedContext> & RequireContextPipeline<InternalHttpCrawlingContext, Context>);
|
|
378
|
+
constructor(options?: HttpCrawlerOptions<Context, ContextExtension, ExtendedContext, Routes, StatisticStateExtension> & RequireContextPipeline<InternalHttpCrawlingContext, Context>);
|
|
379
|
+
/** @internal */
|
|
345
380
|
protected getNavigationTimeoutMillis(): number;
|
|
346
|
-
/**
|
|
347
|
-
* Folds {@link HTTP_OPTIMIZED_CONCURRENCY_SYSTEM_OPTIONS} into the default system, keeping the user's
|
|
348
|
-
* concurrency shortcuts on top. Not called for a supplied
|
|
349
|
-
* {@link BasicCrawlerOptions.concurrencySystem|`concurrencySystem`} — spread the constant into it yourself to
|
|
350
|
-
* keep the tuning.
|
|
351
|
-
*/
|
|
381
|
+
/** @internal */
|
|
352
382
|
protected createDefaultConcurrencySystem(options: ConcurrencySystemOptions): ConcurrencySystem;
|
|
353
383
|
protected buildContextPipeline(): ContextPipeline<CrawlingContext, InternalHttpCrawlingContext>;
|
|
354
|
-
private prepareHttpRequest;
|
|
355
384
|
private makeHttpRequest;
|
|
356
|
-
private processHttpResponse;
|
|
357
|
-
private handleBlockedRequestByContent;
|
|
358
|
-
protected isRequestBlocked(crawlingContext: InternalHttpCrawlingContext): Promise<string | false>;
|
|
359
|
-
/**
|
|
360
|
-
* Function to make the HTTP request. It performs optimizations
|
|
361
|
-
* on the request such as only downloading the request body if the
|
|
362
|
-
* received content type matches text/html, application/xml, application/xhtml+xml.
|
|
363
|
-
*/
|
|
364
|
-
private requestFunction;
|
|
365
|
-
/**
|
|
366
|
-
* Encodes and parses response according to the provided content type
|
|
367
|
-
*/
|
|
368
|
-
private parseResponse;
|
|
369
|
-
/**
|
|
370
|
-
* Combines the provided `requestOptions` with mandatory (non-overridable) values.
|
|
371
|
-
*/
|
|
372
|
-
private getRequestOptions;
|
|
373
|
-
private encodeResponse;
|
|
374
|
-
/**
|
|
375
|
-
* Checks and extends supported mime types
|
|
376
|
-
*/
|
|
377
|
-
private extendSupportedMimeTypes;
|
|
378
|
-
/**
|
|
379
|
-
* Handles timeout request
|
|
380
|
-
*/
|
|
381
|
-
private handleRequestTimeout;
|
|
382
|
-
private _abortDownloadOfBody;
|
|
383
|
-
/**
|
|
384
|
-
* @internal wraps public utility for mocking purposes
|
|
385
|
-
*/
|
|
386
|
-
private _requestAsBrowser;
|
|
387
385
|
}
|
|
388
386
|
/**
|
|
389
387
|
* Creates new {@link Router} instance that works based on request labels.
|