@crawlee/http 4.0.0-beta.1 → 4.0.0-beta.100
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 +132 -228
- package/internals/http-crawler.js +289 -377
- package/internals/utils.d.ts +19 -0
- package/internals/utils.js +81 -0
- package/package.json +10 -9
- 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,72 +1,81 @@
|
|
|
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
|
-
* Timeout
|
|
24
|
+
* Timeout for the whole navigation phase, given in seconds. A single window shared by the
|
|
25
|
+
* `preNavigationHooks`, the navigation (the HTTP request to the resource), and the `postNavigationHooks` -
|
|
26
|
+
* so a slow hook eats into the same budget the navigation uses. Separate from the
|
|
27
|
+
* {@link BasicCrawlerOptions.requestHandlerTimeoutSecs|`requestHandlerTimeoutSecs`}, which times only the
|
|
28
|
+
* request handler.
|
|
25
29
|
*/
|
|
26
30
|
navigationTimeoutSecs?: number;
|
|
27
31
|
/**
|
|
28
32
|
* If set to true, SSL certificate errors will be ignored.
|
|
29
33
|
*/
|
|
30
34
|
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
35
|
/**
|
|
38
36
|
* 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
|
|
37
|
+
* or browser properties before navigation. The function accepts one parameter `crawlingContext`,
|
|
38
|
+
* which is passed to the `requestAsBrowser()` function the crawler calls to navigate.
|
|
39
|
+
*
|
|
40
|
+
* A hook may optionally return a partial object whose properties are merged into the crawling context,
|
|
41
|
+
* allowing the hook to override context members for subsequent hooks and pipeline stages.
|
|
42
|
+
*
|
|
43
|
+
* The context is built up in the following order: base context (`request`, `session`, helpers, ...) ->
|
|
44
|
+
* `extendContext` -> `preNavigationHooks` -> navigation -> `postNavigationHooks` -> `requestHandler`.
|
|
45
|
+
* This means the members added by `extendContext` are already available here, but navigation-dependent
|
|
46
|
+
* members (e.g. `response`, `body`, `$`) are not.
|
|
41
47
|
* Example:
|
|
42
48
|
* ```
|
|
43
49
|
* preNavigationHooks: [
|
|
44
|
-
* async (crawlingContext
|
|
50
|
+
* async (crawlingContext) => {
|
|
45
51
|
* // ...
|
|
46
52
|
* },
|
|
47
53
|
* ]
|
|
48
54
|
* ```
|
|
49
|
-
*
|
|
50
|
-
* Modyfing `pageOptions` is supported only in Playwright incognito.
|
|
51
|
-
* See {@link PrePageCreateHook}
|
|
52
55
|
*/
|
|
53
|
-
preNavigationHooks?: InternalHttpHook<
|
|
56
|
+
preNavigationHooks?: InternalHttpHook<CrawlingContext, ContextExtension>[];
|
|
54
57
|
/**
|
|
55
58
|
* Async functions that are sequentially evaluated after the navigation. Good for checking if the navigation was successful.
|
|
56
59
|
* The function accepts `crawlingContext` as the only parameter.
|
|
60
|
+
*
|
|
61
|
+
* A hook may optionally return a partial object whose properties are merged into the crawling context,
|
|
62
|
+
* which is useful for overriding the `response` after solving a challenge or re-fetching the resource.
|
|
57
63
|
* Example:
|
|
58
64
|
* ```
|
|
59
65
|
* postNavigationHooks: [
|
|
60
66
|
* async (crawlingContext) => {
|
|
61
|
-
*
|
|
67
|
+
* if (await needsRevalidation(crawlingContext)) {
|
|
68
|
+
* return { response: await refetch(crawlingContext.request) };
|
|
69
|
+
* }
|
|
62
70
|
* },
|
|
63
71
|
* ]
|
|
64
72
|
* ```
|
|
65
73
|
*/
|
|
66
|
-
postNavigationHooks?:
|
|
74
|
+
postNavigationHooks?: ((crawlingContext: CrawlingContextWithResponse & ContextExtension) => Awaitable<void | Partial<CrawlingContextWithResponse>>)[];
|
|
67
75
|
/**
|
|
68
76
|
* 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
|
|
77
|
+
* you want the crawler to load and process. By default, only `text/html`, `application/xhtml+xml`, `text/xml`, `application/xml`,
|
|
78
|
+
* and `application/json` MIME types are supported.
|
|
70
79
|
*/
|
|
71
80
|
additionalMimeTypes?: string[];
|
|
72
81
|
/**
|
|
@@ -92,35 +101,28 @@ export interface HttpCrawlerOptions<Context extends InternalHttpCrawlingContext
|
|
|
92
101
|
*/
|
|
93
102
|
forceResponseEncoding?: string;
|
|
94
103
|
/**
|
|
95
|
-
* Automatically saves cookies to Session.
|
|
104
|
+
* Automatically saves cookies to Session. Enabled by default.
|
|
96
105
|
*
|
|
97
106
|
* It parses cookie from response "set-cookie" header saves or updates cookies for session and once the session is used for next request.
|
|
98
107
|
* It passes the "Cookie" header to the request with the session cookies.
|
|
99
108
|
*/
|
|
100
|
-
|
|
109
|
+
saveResponseCookies?: boolean;
|
|
110
|
+
}
|
|
111
|
+
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
|
+
interface CrawlingContextWithResponse<UserData extends Dictionary = any> extends CrawlingContext<UserData> {
|
|
101
115
|
/**
|
|
102
|
-
*
|
|
103
|
-
* By default, status codes >= 500 trigger errors.
|
|
116
|
+
* The request object that was successfully loaded and navigated to, including the {@link Request.loadedUrl|`loadedUrl`} property.
|
|
104
117
|
*/
|
|
105
|
-
|
|
118
|
+
request: LoadedRequest<CrawleeRequest<UserData>>;
|
|
106
119
|
/**
|
|
107
|
-
*
|
|
108
|
-
* By default, status codes >= 500 trigger errors.
|
|
120
|
+
* The HTTP response object containing status code, headers, and other response metadata.
|
|
109
121
|
*/
|
|
110
|
-
|
|
122
|
+
response: Response;
|
|
111
123
|
}
|
|
112
|
-
/**
|
|
113
|
-
* @internal
|
|
114
|
-
*/
|
|
115
|
-
export type InternalHttpHook<Context> = (crawlingContext: Context, gotOptions: OptionsInit) => Awaitable<void>;
|
|
116
|
-
export type HttpHook<UserData extends Dictionary = any, // with default to Dictionary we cant use a typed router in untyped crawler
|
|
117
|
-
JSONData extends JsonValue = any> = InternalHttpHook<HttpCrawlingContext<UserData, JSONData>>;
|
|
118
|
-
/**
|
|
119
|
-
* @internal
|
|
120
|
-
*/
|
|
121
124
|
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> {
|
|
125
|
+
JSONData extends JsonValue = any> extends CrawlingContextWithResponse<UserData> {
|
|
124
126
|
/**
|
|
125
127
|
* The request body of the web page.
|
|
126
128
|
* The type depends on the `Content-Type` header of the web page:
|
|
@@ -139,7 +141,6 @@ Crawler = HttpCrawler<any>> extends CrawlingContext<Crawler, UserData> {
|
|
|
139
141
|
type: string;
|
|
140
142
|
encoding: BufferEncoding;
|
|
141
143
|
};
|
|
142
|
-
response: PlainResponse;
|
|
143
144
|
/**
|
|
144
145
|
* Wait for an element matching the selector to appear. Timeout is ignored.
|
|
145
146
|
*
|
|
@@ -167,7 +168,7 @@ Crawler = HttpCrawler<any>> extends CrawlingContext<Crawler, UserData> {
|
|
|
167
168
|
*/
|
|
168
169
|
parseWithCheerio(selector?: string, timeoutMs?: number): Promise<CheerioRoot>;
|
|
169
170
|
}
|
|
170
|
-
export interface HttpCrawlingContext<UserData extends Dictionary = any, JSONData extends JsonValue = any> extends InternalHttpCrawlingContext<UserData, JSONData
|
|
171
|
+
export interface HttpCrawlingContext<UserData extends Dictionary = any, JSONData extends JsonValue = any> extends InternalHttpCrawlingContext<UserData, JSONData> {
|
|
171
172
|
}
|
|
172
173
|
export type HttpRequestHandler<UserData extends Dictionary = any, // with default to Dictionary we cant use a typed router in untyped crawler
|
|
173
174
|
JSONData extends JsonValue = any> = RequestHandler<HttpCrawlingContext<UserData, JSONData>>;
|
|
@@ -182,38 +183,40 @@ JSONData extends JsonValue = any> = RequestHandler<HttpCrawlingContext<UserData,
|
|
|
182
183
|
*
|
|
183
184
|
* This crawler downloads each URL using a plain HTTP request and doesn't do any HTML parsing.
|
|
184
185
|
*
|
|
185
|
-
* The source URLs are represented using {@link Request} objects that are fed from
|
|
186
|
-
* {@link
|
|
187
|
-
*
|
|
186
|
+
* The source URLs are represented using {@link Request} objects that are fed from the
|
|
187
|
+
* {@link IRequestManager|request manager} provided via the {@link HttpCrawlerOptions.requestManager|`requestManager`}
|
|
188
|
+
* constructor option (a {@link RequestQueue} is itself a request manager). To read from a read-only source such
|
|
189
|
+
* as a {@link RequestList} while still being able to enqueue new requests, combine it with a queue into a
|
|
190
|
+
* {@link RequestManagerTandem} via {@link IRequestLoader.toTandem|`requestLoader.toTandem()`} and pass the
|
|
191
|
+
* result as `requestManager`.
|
|
188
192
|
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
* to {@link RequestQueue} before it starts their processing. This ensures that a single URL is not crawled multiple times.
|
|
193
|
+
* > The {@link HttpCrawlerOptions.requestList|`requestList`} and {@link HttpCrawlerOptions.requestQueue|`requestQueue`}
|
|
194
|
+
* > options are deprecated; they are still accepted and folded into a single `requestManager` for back-compat.
|
|
192
195
|
*
|
|
193
196
|
* The crawler finishes when there are no more {@link Request} objects to crawl.
|
|
194
197
|
*
|
|
195
|
-
* We can use the `preNavigationHooks` to adjust
|
|
198
|
+
* We can use the `preNavigationHooks` to adjust the crawling context before the request is made:
|
|
196
199
|
*
|
|
197
200
|
* ```javascript
|
|
198
201
|
* preNavigationHooks: [
|
|
199
|
-
* (crawlingContext
|
|
202
|
+
* (crawlingContext) => {
|
|
200
203
|
* // ...
|
|
201
204
|
* },
|
|
202
205
|
* ]
|
|
203
206
|
* ```
|
|
204
207
|
*
|
|
205
|
-
* By default, this crawler only processes web pages with the `text/html`
|
|
206
|
-
* and `application/
|
|
208
|
+
* By default, this crawler only processes web pages with the `text/html`, `application/xhtml+xml`, `text/xml`, `application/xml`,
|
|
209
|
+
* and `application/json` MIME content types (as reported by the `Content-Type` HTTP header),
|
|
207
210
|
* and skips pages with other content types. If you want the crawler to process other content types,
|
|
208
211
|
* use the {@link HttpCrawlerOptions.additionalMimeTypes} constructor option.
|
|
209
212
|
* Beware that the parsing behavior differs for HTML, XML, JSON and other types of content.
|
|
210
213
|
* For details, see {@link HttpCrawlerOptions.requestHandler}.
|
|
211
214
|
*
|
|
212
|
-
* New requests are only dispatched when there is enough free CPU and memory available,
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
* {@link
|
|
215
|
+
* New requests are only dispatched when there is enough free CPU and memory available, as judged by the crawler's
|
|
216
|
+
* {@link ConcurrencySystem}.
|
|
217
|
+
* Concurrency is tuned via the `minConcurrency`, `maxConcurrency` and `maxRequestsPerMinute` options of the
|
|
218
|
+
* constructor, or, for finer control, by injecting a pre-configured
|
|
219
|
+
* {@link ConcurrencySystem|`concurrencySystem`}.
|
|
217
220
|
*
|
|
218
221
|
* **Example usage:**
|
|
219
222
|
*
|
|
@@ -238,24 +241,15 @@ JSONData extends JsonValue = any> = RequestHandler<HttpCrawlingContext<UserData,
|
|
|
238
241
|
* ```
|
|
239
242
|
* @category Crawlers
|
|
240
243
|
*/
|
|
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>;
|
|
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']>>> extends BasicCrawler<Context, ContextExtension, ExtendedContext, Routes> {
|
|
245
|
+
private preNavigationHooks;
|
|
246
|
+
private postNavigationHooks;
|
|
247
|
+
private saveResponseCookies;
|
|
248
|
+
private navigationTimeoutMillis;
|
|
249
|
+
private ignoreSslErrors;
|
|
250
|
+
private suggestResponseEncoding?;
|
|
251
|
+
private forceResponseEncoding?;
|
|
252
|
+
private readonly supportedMimeTypes;
|
|
259
253
|
protected static optionsShape: {
|
|
260
254
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
261
255
|
navigationTimeoutSecs: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
@@ -268,17 +262,15 @@ export declare class HttpCrawler<Context extends InternalHttpCrawlingContext<any
|
|
|
268
262
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
269
263
|
forceResponseEncoding: import("ow").StringPredicate & import("ow").BasePredicate<string | undefined>;
|
|
270
264
|
// @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>;
|
|
265
|
+
saveResponseCookies: import("ow").BooleanPredicate & import("ow").BasePredicate<boolean | undefined>;
|
|
278
266
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
279
267
|
preNavigationHooks: import("ow").ArrayPredicate<unknown> & import("ow").BasePredicate<unknown[] | undefined>;
|
|
280
268
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
281
269
|
postNavigationHooks: import("ow").ArrayPredicate<unknown> & import("ow").BasePredicate<unknown[] | undefined>;
|
|
270
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
271
|
+
contextPipelineBuilder: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
272
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
273
|
+
extendContext: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
|
|
282
274
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
283
275
|
requestList: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
284
276
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
@@ -295,28 +287,44 @@ export declare class HttpCrawler<Context extends InternalHttpCrawlingContext<any
|
|
|
295
287
|
maxRequestRetries: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
296
288
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
297
289
|
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
290
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
301
291
|
maxRequestsPerCrawl: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
302
292
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
303
|
-
|
|
293
|
+
maxCrawlDepth: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
294
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
295
|
+
taskLoopOptions: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
296
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
297
|
+
concurrencySystem: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
304
298
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
305
|
-
|
|
299
|
+
sessionPool: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
306
300
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
307
|
-
|
|
301
|
+
proxyConfiguration: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
308
302
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
309
303
|
statusMessageLoggingInterval: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
310
304
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
311
305
|
statusMessageCallback: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
|
|
306
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
307
|
+
additionalHttpErrorStatusCodes: import("ow").ArrayPredicate<number>;
|
|
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
312
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
313
313
|
retryOnBlocked: import("ow").BooleanPredicate & import("ow").BasePredicate<boolean | undefined>;
|
|
314
314
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
315
|
-
respectRobotsTxtFile: import("ow").
|
|
315
|
+
respectRobotsTxtFile: import("ow").AnyPredicate<boolean | object>;
|
|
316
316
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
317
317
|
onSkippedRequest: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
|
|
318
318
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
319
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>;
|
|
320
328
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
321
329
|
minConcurrency: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
322
330
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
@@ -325,162 +333,58 @@ export declare class HttpCrawler<Context extends InternalHttpCrawlingContext<any
|
|
|
325
333
|
maxRequestsPerMinute: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
326
334
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
327
335
|
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
336
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
333
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>;
|
|
334
340
|
};
|
|
335
341
|
/**
|
|
336
342
|
* All `HttpCrawlerOptions` parameters are passed via an options object.
|
|
337
343
|
*/
|
|
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;
|
|
345
|
-
/**
|
|
346
|
-
* Wrapper around requestHandler that opens and closes pages etc.
|
|
347
|
-
*/
|
|
348
|
-
protected _runRequestHandler(crawlingContext: Context): Promise<void>;
|
|
349
|
-
protected isRequestBlocked(crawlingContext: Context): Promise<string | false>;
|
|
350
|
-
protected _handleNavigation(crawlingContext: Context): Promise<void>;
|
|
344
|
+
constructor(options?: HttpCrawlerOptions<Context, ContextExtension, ExtendedContext> & RequireContextPipeline<InternalHttpCrawlingContext, Context>);
|
|
345
|
+
protected getNavigationTimeoutMillis(): number;
|
|
351
346
|
/**
|
|
352
|
-
*
|
|
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.
|
|
353
351
|
*/
|
|
354
|
-
protected
|
|
352
|
+
protected createDefaultConcurrencySystem(options: ConcurrencySystemOptions): ConcurrencySystem;
|
|
353
|
+
protected buildContextPipeline(): ContextPipeline<CrawlingContext, InternalHttpCrawlingContext>;
|
|
354
|
+
private prepareHttpRequest;
|
|
355
|
+
private makeHttpRequest;
|
|
356
|
+
private processHttpResponse;
|
|
357
|
+
private handleBlockedRequestByContent;
|
|
358
|
+
protected isRequestBlocked(crawlingContext: InternalHttpCrawlingContext): Promise<string | false>;
|
|
355
359
|
/**
|
|
356
360
|
* Function to make the HTTP request. It performs optimizations
|
|
357
361
|
* on the request such as only downloading the request body if the
|
|
358
362
|
* received content type matches text/html, application/xml, application/xhtml+xml.
|
|
359
363
|
*/
|
|
360
|
-
|
|
364
|
+
private requestFunction;
|
|
361
365
|
/**
|
|
362
366
|
* Encodes and parses response according to the provided content type
|
|
363
367
|
*/
|
|
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>>;
|
|
368
|
+
private parseResponse;
|
|
384
369
|
/**
|
|
385
370
|
* Combines the provided `requestOptions` with mandatory (non-overridable) values.
|
|
386
371
|
*/
|
|
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
|
-
};
|
|
372
|
+
private getRequestOptions;
|
|
373
|
+
private encodeResponse;
|
|
464
374
|
/**
|
|
465
375
|
* Checks and extends supported mime types
|
|
466
376
|
*/
|
|
467
|
-
|
|
377
|
+
private extendSupportedMimeTypes;
|
|
468
378
|
/**
|
|
469
379
|
* Handles timeout request
|
|
470
380
|
*/
|
|
471
|
-
|
|
381
|
+
private handleRequestTimeout;
|
|
472
382
|
private _abortDownloadOfBody;
|
|
473
383
|
/**
|
|
474
384
|
* @internal wraps public utility for mocking purposes
|
|
475
385
|
*/
|
|
476
386
|
private _requestAsBrowser;
|
|
477
387
|
}
|
|
478
|
-
interface RequestFunctionOptions {
|
|
479
|
-
request: Request;
|
|
480
|
-
session?: Session;
|
|
481
|
-
proxyUrl?: string;
|
|
482
|
-
gotOptions: OptionsInit;
|
|
483
|
-
}
|
|
484
388
|
/**
|
|
485
389
|
* Creates new {@link Router} instance that works based on request labels.
|
|
486
390
|
* This instance can then serve as a `requestHandler` of your {@link HttpCrawler}.
|
|
@@ -505,7 +409,7 @@ interface RequestFunctionOptions {
|
|
|
505
409
|
* await crawler.run();
|
|
506
410
|
* ```
|
|
507
411
|
*/
|
|
508
|
-
|
|
509
|
-
export declare function createHttpRouter<Context extends HttpCrawlingContext = HttpCrawlingContext, UserData extends Dictionary = GetUserDataFromRequest<Context['request']>>(routes?: RouterRoutes<Context, UserData
|
|
412
|
+
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>;
|
|
413
|
+
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>>;
|
|
414
|
+
export declare function createHttpRouter<Context extends HttpCrawlingContext = HttpCrawlingContext, const Schemas extends RouteSchemas = RouteSchemas>(schemas: Schemas): RouterHandler<Context, RoutesFromSchemas<Schemas>>;
|
|
510
415
|
export {};
|
|
511
|
-
//# sourceMappingURL=http-crawler.d.ts.map
|