@crawlee/http 4.0.0-beta.9 → 4.0.0-beta.91
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 +61 -35
- package/internals/file-download.js +119 -77
- package/internals/http-crawler.d.ts +125 -220
- package/internals/http-crawler.js +256 -374
- package/internals/utils.d.ts +19 -0
- package/internals/utils.js +81 -0
- package/package.json +9 -8
- 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/tsconfig.build.tsbuildinfo +0 -1
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { BasicCrawler, Configuration, CrawlerExtension } from '@crawlee/basic';
|
|
5
|
-
import type { HttpResponse } 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
5
|
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';
|
|
11
|
-
import { ObjectPredicate } from 'ow';
|
|
12
6
|
import type { JsonValue } from 'type-fest';
|
|
13
7
|
/**
|
|
14
|
-
*
|
|
15
|
-
* @
|
|
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.
|
|
10
|
+
*
|
|
11
|
+
* A {@link BasicCrawlerOptions.concurrencySystem|`concurrencySystem`} you supply yourself replaces that default
|
|
12
|
+
* wholesale, tuning included, so spread these options in if you want to keep it:
|
|
13
|
+
*
|
|
14
|
+
* ```typescript
|
|
15
|
+
* new ConcurrencySystem({ ...HTTP_OPTIMIZED_CONCURRENCY_SYSTEM_OPTIONS, maxConcurrency: 50 });
|
|
16
|
+
* ```
|
|
16
17
|
*/
|
|
17
|
-
export
|
|
18
|
-
body?: unknown;
|
|
19
|
-
};
|
|
18
|
+
export declare const HTTP_OPTIMIZED_CONCURRENCY_SYSTEM_OPTIONS: ConcurrencySystemOptions;
|
|
20
19
|
export type HttpErrorHandler<UserData extends Dictionary = any, // with default to Dictionary we cant use a typed router in untyped crawler
|
|
21
|
-
JSONData extends JsonValue = any
|
|
22
|
-
|
|
20
|
+
JSONData extends JsonValue = any, // with default to Dictionary we cant use a typed router in untyped crawler
|
|
21
|
+
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']>>> extends BasicCrawlerOptions<Context, ContextExtension, ExtendedContext, Routes> {
|
|
23
23
|
/**
|
|
24
24
|
* Timeout in which the HTTP request to the resource needs to finish, given in seconds.
|
|
25
25
|
*/
|
|
@@ -28,45 +28,50 @@ export interface HttpCrawlerOptions<Context extends InternalHttpCrawlingContext
|
|
|
28
28
|
* If set to true, SSL certificate errors will be ignored.
|
|
29
29
|
*/
|
|
30
30
|
ignoreSslErrors?: boolean;
|
|
31
|
-
/**
|
|
32
|
-
* If set, this crawler will be configured for all connections to use
|
|
33
|
-
* [Apify Proxy](https://console.apify.com/proxy) or your own Proxy URLs provided and rotated according to the configuration.
|
|
34
|
-
* For more information, see the [documentation](https://docs.apify.com/proxy).
|
|
35
|
-
*/
|
|
36
|
-
proxyConfiguration?: ProxyConfiguration;
|
|
37
31
|
/**
|
|
38
32
|
* Async functions that are sequentially evaluated before the navigation. Good for setting additional cookies
|
|
39
|
-
* or browser properties before navigation. The function accepts
|
|
40
|
-
* which
|
|
33
|
+
* or browser properties before navigation. The function accepts one parameter `crawlingContext`,
|
|
34
|
+
* which is passed to the `requestAsBrowser()` function the crawler calls to navigate.
|
|
35
|
+
*
|
|
36
|
+
* A hook may optionally return a partial object whose properties are merged into the crawling context,
|
|
37
|
+
* allowing the hook to override context members for subsequent hooks and pipeline stages.
|
|
38
|
+
*
|
|
39
|
+
* The context is built up in the following order: base context (`request`, `session`, helpers, ...) ->
|
|
40
|
+
* `extendContext` -> `preNavigationHooks` -> navigation -> `postNavigationHooks` -> `requestHandler`.
|
|
41
|
+
* This means the members added by `extendContext` are already available here, but navigation-dependent
|
|
42
|
+
* members (e.g. `response`, `body`, `$`) are not.
|
|
41
43
|
* Example:
|
|
42
44
|
* ```
|
|
43
45
|
* preNavigationHooks: [
|
|
44
|
-
* async (crawlingContext
|
|
46
|
+
* async (crawlingContext) => {
|
|
45
47
|
* // ...
|
|
46
48
|
* },
|
|
47
49
|
* ]
|
|
48
50
|
* ```
|
|
49
|
-
*
|
|
50
|
-
* Modyfing `pageOptions` is supported only in Playwright incognito.
|
|
51
|
-
* See {@link PrePageCreateHook}
|
|
52
51
|
*/
|
|
53
|
-
preNavigationHooks?: InternalHttpHook<
|
|
52
|
+
preNavigationHooks?: InternalHttpHook<CrawlingContext, ContextExtension>[];
|
|
54
53
|
/**
|
|
55
54
|
* Async functions that are sequentially evaluated after the navigation. Good for checking if the navigation was successful.
|
|
56
55
|
* The function accepts `crawlingContext` as the only parameter.
|
|
56
|
+
*
|
|
57
|
+
* A hook may optionally return a partial object whose properties are merged into the crawling context,
|
|
58
|
+
* which is useful for overriding the `response` after solving a challenge or re-fetching the resource.
|
|
57
59
|
* Example:
|
|
58
60
|
* ```
|
|
59
61
|
* postNavigationHooks: [
|
|
60
62
|
* async (crawlingContext) => {
|
|
61
|
-
*
|
|
63
|
+
* if (await needsRevalidation(crawlingContext)) {
|
|
64
|
+
* return { response: await refetch(crawlingContext.request) };
|
|
65
|
+
* }
|
|
62
66
|
* },
|
|
63
67
|
* ]
|
|
64
68
|
* ```
|
|
65
69
|
*/
|
|
66
|
-
postNavigationHooks?:
|
|
70
|
+
postNavigationHooks?: ((crawlingContext: CrawlingContextWithResponse & ContextExtension) => Awaitable<void | Partial<CrawlingContextWithResponse>>)[];
|
|
67
71
|
/**
|
|
68
72
|
* An array of [MIME types](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Complete_list_of_MIME_types)
|
|
69
|
-
* you want the crawler to load and process. By default, only `text/html
|
|
73
|
+
* you want the crawler to load and process. By default, only `text/html`, `application/xhtml+xml`, `text/xml`, `application/xml`,
|
|
74
|
+
* and `application/json` MIME types are supported.
|
|
70
75
|
*/
|
|
71
76
|
additionalMimeTypes?: string[];
|
|
72
77
|
/**
|
|
@@ -92,35 +97,34 @@ export interface HttpCrawlerOptions<Context extends InternalHttpCrawlingContext
|
|
|
92
97
|
*/
|
|
93
98
|
forceResponseEncoding?: string;
|
|
94
99
|
/**
|
|
95
|
-
* Automatically saves cookies to Session.
|
|
100
|
+
* Automatically saves cookies to Session. Enabled by default.
|
|
96
101
|
*
|
|
97
102
|
* It parses cookie from response "set-cookie" header saves or updates cookies for session and once the session is used for next request.
|
|
98
103
|
* It passes the "Cookie" header to the request with the session cookies.
|
|
99
104
|
*/
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* An array of HTTP response [Status Codes](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status) to be excluded from error consideration.
|
|
103
|
-
* By default, status codes >= 500 trigger errors.
|
|
104
|
-
*/
|
|
105
|
-
ignoreHttpErrorStatusCodes?: number[];
|
|
106
|
-
/**
|
|
107
|
-
* An array of additional HTTP response [Status Codes](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status) to be treated as errors.
|
|
108
|
-
* By default, status codes >= 500 trigger errors.
|
|
109
|
-
*/
|
|
110
|
-
additionalHttpErrorStatusCodes?: number[];
|
|
105
|
+
saveResponseCookies?: boolean;
|
|
111
106
|
}
|
|
112
107
|
/**
|
|
113
108
|
* @internal
|
|
114
109
|
*/
|
|
115
|
-
export type InternalHttpHook<Context> = (crawlingContext: Context
|
|
110
|
+
export type InternalHttpHook<Context, ContextExtension = {}> = (crawlingContext: Context & ContextExtension) => Awaitable<void | Partial<Context>>;
|
|
116
111
|
export type HttpHook<UserData extends Dictionary = any, // with default to Dictionary we cant use a typed router in untyped crawler
|
|
117
112
|
JSONData extends JsonValue = any> = InternalHttpHook<HttpCrawlingContext<UserData, JSONData>>;
|
|
113
|
+
interface CrawlingContextWithResponse<UserData extends Dictionary = any> extends CrawlingContext<UserData> {
|
|
114
|
+
/**
|
|
115
|
+
* The request object that was successfully loaded and navigated to, including the {@link Request.loadedUrl|`loadedUrl`} property.
|
|
116
|
+
*/
|
|
117
|
+
request: LoadedRequest<CrawleeRequest<UserData>>;
|
|
118
|
+
/**
|
|
119
|
+
* The HTTP response object containing status code, headers, and other response metadata.
|
|
120
|
+
*/
|
|
121
|
+
response: Response;
|
|
122
|
+
}
|
|
118
123
|
/**
|
|
119
124
|
* @internal
|
|
120
125
|
*/
|
|
121
126
|
export interface InternalHttpCrawlingContext<UserData extends Dictionary = any, // with default to Dictionary we cant use a typed router in untyped crawler
|
|
122
|
-
JSONData extends JsonValue = any
|
|
123
|
-
Crawler = HttpCrawler<any>> extends CrawlingContext<Crawler, UserData> {
|
|
127
|
+
JSONData extends JsonValue = any> extends CrawlingContextWithResponse<UserData> {
|
|
124
128
|
/**
|
|
125
129
|
* The request body of the web page.
|
|
126
130
|
* The type depends on the `Content-Type` header of the web page:
|
|
@@ -139,7 +143,6 @@ Crawler = HttpCrawler<any>> extends CrawlingContext<Crawler, UserData> {
|
|
|
139
143
|
type: string;
|
|
140
144
|
encoding: BufferEncoding;
|
|
141
145
|
};
|
|
142
|
-
response: PlainResponse;
|
|
143
146
|
/**
|
|
144
147
|
* Wait for an element matching the selector to appear. Timeout is ignored.
|
|
145
148
|
*
|
|
@@ -167,7 +170,7 @@ Crawler = HttpCrawler<any>> extends CrawlingContext<Crawler, UserData> {
|
|
|
167
170
|
*/
|
|
168
171
|
parseWithCheerio(selector?: string, timeoutMs?: number): Promise<CheerioRoot>;
|
|
169
172
|
}
|
|
170
|
-
export interface HttpCrawlingContext<UserData extends Dictionary = any, JSONData extends JsonValue = any> extends InternalHttpCrawlingContext<UserData, JSONData
|
|
173
|
+
export interface HttpCrawlingContext<UserData extends Dictionary = any, JSONData extends JsonValue = any> extends InternalHttpCrawlingContext<UserData, JSONData> {
|
|
171
174
|
}
|
|
172
175
|
export type HttpRequestHandler<UserData extends Dictionary = any, // with default to Dictionary we cant use a typed router in untyped crawler
|
|
173
176
|
JSONData extends JsonValue = any> = RequestHandler<HttpCrawlingContext<UserData, JSONData>>;
|
|
@@ -182,28 +185,30 @@ JSONData extends JsonValue = any> = RequestHandler<HttpCrawlingContext<UserData,
|
|
|
182
185
|
*
|
|
183
186
|
* This crawler downloads each URL using a plain HTTP request and doesn't do any HTML parsing.
|
|
184
187
|
*
|
|
185
|
-
* The source URLs are represented using {@link Request} objects that are fed from
|
|
186
|
-
* {@link
|
|
187
|
-
*
|
|
188
|
+
* The source URLs are represented using {@link Request} objects that are fed from the
|
|
189
|
+
* {@link IRequestManager|request manager} provided via the {@link HttpCrawlerOptions.requestManager|`requestManager`}
|
|
190
|
+
* constructor option (a {@link RequestQueue} is itself a request manager). To read from a read-only source such
|
|
191
|
+
* as a {@link RequestList} while still being able to enqueue new requests, combine it with a queue into a
|
|
192
|
+
* {@link RequestManagerTandem} via {@link IRequestLoader.toTandem|`requestLoader.toTandem()`} and pass the
|
|
193
|
+
* result as `requestManager`.
|
|
188
194
|
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
* to {@link RequestQueue} before it starts their processing. This ensures that a single URL is not crawled multiple times.
|
|
195
|
+
* > The {@link HttpCrawlerOptions.requestList|`requestList`} and {@link HttpCrawlerOptions.requestQueue|`requestQueue`}
|
|
196
|
+
* > options are deprecated; they are still accepted and folded into a single `requestManager` for back-compat.
|
|
192
197
|
*
|
|
193
198
|
* The crawler finishes when there are no more {@link Request} objects to crawl.
|
|
194
199
|
*
|
|
195
|
-
* We can use the `preNavigationHooks` to adjust
|
|
200
|
+
* We can use the `preNavigationHooks` to adjust the crawling context before the request is made:
|
|
196
201
|
*
|
|
197
202
|
* ```javascript
|
|
198
203
|
* preNavigationHooks: [
|
|
199
|
-
* (crawlingContext
|
|
204
|
+
* (crawlingContext) => {
|
|
200
205
|
* // ...
|
|
201
206
|
* },
|
|
202
207
|
* ]
|
|
203
208
|
* ```
|
|
204
209
|
*
|
|
205
|
-
* By default, this crawler only processes web pages with the `text/html`
|
|
206
|
-
* and `application/
|
|
210
|
+
* By default, this crawler only processes web pages with the `text/html`, `application/xhtml+xml`, `text/xml`, `application/xml`,
|
|
211
|
+
* and `application/json` MIME content types (as reported by the `Content-Type` HTTP header),
|
|
207
212
|
* and skips pages with other content types. If you want the crawler to process other content types,
|
|
208
213
|
* use the {@link HttpCrawlerOptions.additionalMimeTypes} constructor option.
|
|
209
214
|
* Beware that the parsing behavior differs for HTML, XML, JSON and other types of content.
|
|
@@ -211,9 +216,9 @@ JSONData extends JsonValue = any> = RequestHandler<HttpCrawlingContext<UserData,
|
|
|
211
216
|
*
|
|
212
217
|
* New requests are only dispatched when there is enough free CPU and memory available,
|
|
213
218
|
* using the functionality provided by the {@link AutoscaledPool} class.
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
* {@link
|
|
219
|
+
* Concurrency is tuned via the `minConcurrency`, `maxConcurrency` and `maxRequestsPerMinute` options of the
|
|
220
|
+
* constructor, or, for finer control, by injecting a pre-configured
|
|
221
|
+
* {@link ConcurrencySystem|`concurrencySystem`}.
|
|
217
222
|
*
|
|
218
223
|
* **Example usage:**
|
|
219
224
|
*
|
|
@@ -238,24 +243,15 @@ JSONData extends JsonValue = any> = RequestHandler<HttpCrawlingContext<UserData,
|
|
|
238
243
|
* ```
|
|
239
244
|
* @category Crawlers
|
|
240
245
|
*/
|
|
241
|
-
export declare class HttpCrawler<Context extends InternalHttpCrawlingContext<any, any,
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
protected postNavigationHooks: InternalHttpHook<Context>[];
|
|
251
|
-
protected persistCookiesPerSession: boolean;
|
|
252
|
-
protected navigationTimeoutMillis: number;
|
|
253
|
-
protected ignoreSslErrors: boolean;
|
|
254
|
-
protected suggestResponseEncoding?: string;
|
|
255
|
-
protected forceResponseEncoding?: string;
|
|
256
|
-
protected additionalHttpErrorStatusCodes: Set<number>;
|
|
257
|
-
protected ignoreHttpErrorStatusCodes: Set<number>;
|
|
258
|
-
protected readonly supportedMimeTypes: Set<string>;
|
|
246
|
+
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']>>> extends BasicCrawler<Context, ContextExtension, ExtendedContext, Routes> {
|
|
247
|
+
private preNavigationHooks;
|
|
248
|
+
private postNavigationHooks;
|
|
249
|
+
private saveResponseCookies;
|
|
250
|
+
private navigationTimeoutMillis;
|
|
251
|
+
private ignoreSslErrors;
|
|
252
|
+
private suggestResponseEncoding?;
|
|
253
|
+
private forceResponseEncoding?;
|
|
254
|
+
private readonly supportedMimeTypes;
|
|
259
255
|
protected static optionsShape: {
|
|
260
256
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
261
257
|
navigationTimeoutSecs: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
@@ -268,17 +264,15 @@ export declare class HttpCrawler<Context extends InternalHttpCrawlingContext<any
|
|
|
268
264
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
269
265
|
forceResponseEncoding: import("ow").StringPredicate & import("ow").BasePredicate<string | undefined>;
|
|
270
266
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
271
|
-
|
|
272
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
273
|
-
persistCookiesPerSession: import("ow").BooleanPredicate & import("ow").BasePredicate<boolean | undefined>;
|
|
274
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
275
|
-
additionalHttpErrorStatusCodes: import("ow").ArrayPredicate<number>;
|
|
276
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
277
|
-
ignoreHttpErrorStatusCodes: import("ow").ArrayPredicate<number>;
|
|
267
|
+
saveResponseCookies: import("ow").BooleanPredicate & import("ow").BasePredicate<boolean | undefined>;
|
|
278
268
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
279
269
|
preNavigationHooks: import("ow").ArrayPredicate<unknown> & import("ow").BasePredicate<unknown[] | undefined>;
|
|
280
270
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
281
271
|
postNavigationHooks: import("ow").ArrayPredicate<unknown> & import("ow").BasePredicate<unknown[] | undefined>;
|
|
272
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
273
|
+
contextPipelineBuilder: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
274
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
275
|
+
extendContext: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
|
|
282
276
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
283
277
|
requestList: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
284
278
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
@@ -295,28 +289,44 @@ export declare class HttpCrawler<Context extends InternalHttpCrawlingContext<any
|
|
|
295
289
|
maxRequestRetries: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
296
290
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
297
291
|
sameDomainDelaySecs: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
298
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
299
|
-
maxSessionRotations: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
300
292
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
301
293
|
maxRequestsPerCrawl: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
294
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
295
|
+
maxCrawlDepth: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
302
296
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
303
297
|
autoscaledPoolOptions: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
304
298
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
305
|
-
|
|
299
|
+
concurrencySystem: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
306
300
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
307
|
-
|
|
301
|
+
sessionPool: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
302
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
303
|
+
proxyConfiguration: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
308
304
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
309
305
|
statusMessageLoggingInterval: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
310
306
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
311
307
|
statusMessageCallback: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
|
|
308
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
309
|
+
additionalHttpErrorStatusCodes: import("ow").ArrayPredicate<number>;
|
|
310
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
311
|
+
ignoreHttpErrorStatusCodes: import("ow").ArrayPredicate<number>;
|
|
312
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
313
|
+
blockedStatusCodes: import("ow").ArrayPredicate<number>;
|
|
312
314
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
313
315
|
retryOnBlocked: import("ow").BooleanPredicate & import("ow").BasePredicate<boolean | undefined>;
|
|
314
316
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
315
|
-
respectRobotsTxtFile: import("ow").
|
|
317
|
+
respectRobotsTxtFile: import("ow").AnyPredicate<boolean | object>;
|
|
316
318
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
317
319
|
onSkippedRequest: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
|
|
318
320
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
319
321
|
httpClient: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
322
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
323
|
+
configuration: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
324
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
325
|
+
storageBackend: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
326
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
327
|
+
eventManager: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
328
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
329
|
+
logger: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
320
330
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
321
331
|
minConcurrency: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
322
332
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
@@ -325,162 +335,57 @@ export declare class HttpCrawler<Context extends InternalHttpCrawlingContext<any
|
|
|
325
335
|
maxRequestsPerMinute: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
326
336
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
327
337
|
keepAlive: import("ow").BooleanPredicate & import("ow").BasePredicate<boolean | undefined>;
|
|
328
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
329
|
-
log: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
330
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
331
|
-
experiments: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
332
338
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
333
339
|
statisticsOptions: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
340
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
341
|
+
id: import("ow").StringPredicate & import("ow").BasePredicate<string | undefined>;
|
|
334
342
|
};
|
|
335
343
|
/**
|
|
336
344
|
* All `HttpCrawlerOptions` parameters are passed via an options object.
|
|
337
345
|
*/
|
|
338
|
-
constructor(options?: HttpCrawlerOptions<Context
|
|
339
|
-
/**
|
|
340
|
-
* **EXPERIMENTAL**
|
|
341
|
-
* Function for attaching CrawlerExtensions such as the Unblockers.
|
|
342
|
-
* @param extension Crawler extension that overrides the crawler configuration.
|
|
343
|
-
*/
|
|
344
|
-
use(extension: CrawlerExtension): void;
|
|
346
|
+
constructor(options?: HttpCrawlerOptions<Context, ContextExtension, ExtendedContext> & RequireContextPipeline<InternalHttpCrawlingContext, Context>);
|
|
345
347
|
/**
|
|
346
|
-
*
|
|
348
|
+
* Folds {@link HTTP_OPTIMIZED_CONCURRENCY_SYSTEM_OPTIONS} into the default system, keeping the user's
|
|
349
|
+
* concurrency shortcuts on top. Not called for a supplied
|
|
350
|
+
* {@link BasicCrawlerOptions.concurrencySystem|`concurrencySystem`} — spread the constant into it yourself to
|
|
351
|
+
* keep the tuning.
|
|
347
352
|
*/
|
|
348
|
-
protected
|
|
349
|
-
protected
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
protected
|
|
353
|
+
protected createDefaultConcurrencySystem(options: ConcurrencySystemOptions): ConcurrencySystem;
|
|
354
|
+
protected buildContextPipeline(): ContextPipeline<CrawlingContext, InternalHttpCrawlingContext>;
|
|
355
|
+
private prepareHttpRequest;
|
|
356
|
+
private makeHttpRequest;
|
|
357
|
+
private processHttpResponse;
|
|
358
|
+
private handleBlockedRequestByContent;
|
|
359
|
+
protected isRequestBlocked(crawlingContext: InternalHttpCrawlingContext): Promise<string | false>;
|
|
355
360
|
/**
|
|
356
361
|
* Function to make the HTTP request. It performs optimizations
|
|
357
362
|
* on the request such as only downloading the request body if the
|
|
358
363
|
* received content type matches text/html, application/xml, application/xhtml+xml.
|
|
359
364
|
*/
|
|
360
|
-
|
|
365
|
+
private requestFunction;
|
|
361
366
|
/**
|
|
362
367
|
* Encodes and parses response according to the provided content type
|
|
363
368
|
*/
|
|
364
|
-
|
|
365
|
-
isXml: boolean;
|
|
366
|
-
response: IncomingMessage;
|
|
367
|
-
contentType: {
|
|
368
|
-
type: string;
|
|
369
|
-
encoding: BufferEncoding;
|
|
370
|
-
};
|
|
371
|
-
}) | {
|
|
372
|
-
body: Buffer<ArrayBufferLike>;
|
|
373
|
-
response: IncomingMessage;
|
|
374
|
-
contentType: {
|
|
375
|
-
type: string;
|
|
376
|
-
encoding: BufferEncoding;
|
|
377
|
-
};
|
|
378
|
-
enqueueLinks: () => Promise<{
|
|
379
|
-
processedRequests: never[];
|
|
380
|
-
unprocessedRequests: never[];
|
|
381
|
-
}>;
|
|
382
|
-
}>;
|
|
383
|
-
protected _parseHTML(response: IncomingMessage, _isXml: boolean, _crawlingContext: Context): Promise<Partial<Context>>;
|
|
369
|
+
private parseResponse;
|
|
384
370
|
/**
|
|
385
371
|
* Combines the provided `requestOptions` with mandatory (non-overridable) values.
|
|
386
372
|
*/
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
body?: string | Buffer | Readable | Generator | AsyncGenerator | import("form-data-encoder").FormDataLike | undefined;
|
|
390
|
-
json?: unknown;
|
|
391
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
392
|
-
request?: import("got-scraping").RequestFunction | undefined;
|
|
393
|
-
url?: string | URL | undefined;
|
|
394
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
395
|
-
headers?: import("got-scraping").Headers | undefined;
|
|
396
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
397
|
-
agent?: import("got-scraping").Agents | undefined;
|
|
398
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
399
|
-
h2session?: import("http2").ClientHttp2Session | undefined;
|
|
400
|
-
decompress?: boolean | undefined;
|
|
401
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
402
|
-
timeout?: import("got-scraping").Delays | undefined;
|
|
403
|
-
prefixUrl?: string | URL | undefined;
|
|
404
|
-
form?: Record<string, any> | undefined;
|
|
405
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
406
|
-
cookieJar?: import("got-scraping").PromiseCookieJar | import("got-scraping").ToughCookieJar | undefined;
|
|
407
|
-
signal?: AbortSignal | undefined;
|
|
408
|
-
ignoreInvalidCookies?: boolean | undefined;
|
|
409
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
410
|
-
searchParams?: string | import("got-scraping").SearchParameters | URLSearchParams | undefined;
|
|
411
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
412
|
-
dnsLookup?: import("cacheable-lookup").default["lookup"] | undefined;
|
|
413
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
414
|
-
dnsCache?: import("cacheable-lookup").default | boolean | undefined;
|
|
415
|
-
context?: Record<string, unknown> | undefined;
|
|
416
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
417
|
-
followRedirect?: boolean | ((response: import("got-scraping").PlainResponse) => boolean) | undefined;
|
|
418
|
-
maxRedirects?: number | undefined;
|
|
419
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
420
|
-
cache?: string | import("cacheable-request").StorageAdapter | boolean | undefined;
|
|
421
|
-
throwHttpErrors?: boolean | undefined;
|
|
422
|
-
username?: string | undefined;
|
|
423
|
-
password?: string | undefined;
|
|
424
|
-
http2?: boolean | undefined;
|
|
425
|
-
allowGetBody?: boolean | undefined;
|
|
426
|
-
methodRewriting?: boolean | undefined;
|
|
427
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
428
|
-
dnsLookupIpVersion?: import("got-scraping").DnsLookupIpVersion;
|
|
429
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
430
|
-
parseJson?: import("got-scraping").ParseJsonFunction | undefined;
|
|
431
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
432
|
-
stringifyJson?: import("got-scraping").StringifyJsonFunction | undefined;
|
|
433
|
-
localAddress?: string | undefined;
|
|
434
|
-
method?: Method | undefined;
|
|
435
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
436
|
-
createConnection?: import("got-scraping").CreateConnectionFunction | undefined;
|
|
437
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
438
|
-
cacheOptions?: import("got-scraping").CacheOptions | undefined;
|
|
439
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
440
|
-
https?: import("got-scraping").HttpsOptions | undefined;
|
|
441
|
-
encoding?: BufferEncoding | undefined;
|
|
442
|
-
resolveBodyOnly?: boolean | undefined;
|
|
443
|
-
isStream?: boolean | undefined;
|
|
444
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
445
|
-
responseType?: import("got-scraping").ResponseType | undefined;
|
|
446
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
447
|
-
pagination?: import("got-scraping").PaginationOptions<unknown, unknown> | undefined;
|
|
448
|
-
setHost?: boolean | undefined;
|
|
449
|
-
maxHeaderSize?: number | undefined;
|
|
450
|
-
enableUnixSockets?: boolean | undefined;
|
|
451
|
-
} & {
|
|
452
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
453
|
-
hooks?: Partial<import("got-scraping").Hooks>;
|
|
454
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
455
|
-
retry?: Partial<import("got-scraping").RetryOptions>;
|
|
456
|
-
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
457
|
-
} & import("got-scraping").Context & Required<Pick<OptionsInit, "url">> & {
|
|
458
|
-
isStream: true;
|
|
459
|
-
};
|
|
460
|
-
protected _encodeResponse(request: Request, response: IncomingMessage, encoding: BufferEncoding): {
|
|
461
|
-
encoding: BufferEncoding;
|
|
462
|
-
response: IncomingMessage;
|
|
463
|
-
};
|
|
373
|
+
private getRequestOptions;
|
|
374
|
+
private encodeResponse;
|
|
464
375
|
/**
|
|
465
376
|
* Checks and extends supported mime types
|
|
466
377
|
*/
|
|
467
|
-
|
|
378
|
+
private extendSupportedMimeTypes;
|
|
468
379
|
/**
|
|
469
380
|
* Handles timeout request
|
|
470
381
|
*/
|
|
471
|
-
|
|
382
|
+
private handleRequestTimeout;
|
|
472
383
|
private _abortDownloadOfBody;
|
|
473
384
|
/**
|
|
474
385
|
* @internal wraps public utility for mocking purposes
|
|
475
386
|
*/
|
|
476
387
|
private _requestAsBrowser;
|
|
477
388
|
}
|
|
478
|
-
interface RequestFunctionOptions {
|
|
479
|
-
request: Request;
|
|
480
|
-
session?: Session;
|
|
481
|
-
proxyUrl?: string;
|
|
482
|
-
gotOptions: OptionsInit;
|
|
483
|
-
}
|
|
484
389
|
/**
|
|
485
390
|
* Creates new {@link Router} instance that works based on request labels.
|
|
486
391
|
* This instance can then serve as a `requestHandler` of your {@link HttpCrawler}.
|
|
@@ -505,7 +410,7 @@ interface RequestFunctionOptions {
|
|
|
505
410
|
* await crawler.run();
|
|
506
411
|
* ```
|
|
507
412
|
*/
|
|
508
|
-
|
|
509
|
-
export declare function createHttpRouter<Context extends HttpCrawlingContext = HttpCrawlingContext, UserData extends Dictionary = GetUserDataFromRequest<Context['request']>>(routes?: RouterRoutes<Context, UserData
|
|
413
|
+
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>;
|
|
414
|
+
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>>;
|
|
415
|
+
export declare function createHttpRouter<Context extends HttpCrawlingContext = HttpCrawlingContext, const Schemas extends RouteSchemas = RouteSchemas>(schemas: Schemas): RouterHandler<Context, RoutesFromSchemas<Schemas>>;
|
|
510
416
|
export {};
|
|
511
|
-
//# sourceMappingURL=http-crawler.d.ts.map
|