@crawlee/http 4.0.0-beta.8 → 4.0.0-beta.81
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 +60 -34
- package/internals/file-download.js +118 -76
- package/internals/http-crawler.d.ts +100 -221
- package/internals/http-crawler.js +216 -363
- 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,13 @@
|
|
|
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, 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
|
-
/**
|
|
14
|
-
* TODO exists for BC within HttpCrawler - replace completely with StreamingHttpResponse in 4.0
|
|
15
|
-
* @internal
|
|
16
|
-
*/
|
|
17
|
-
export type PlainResponse = Omit<HttpResponse, 'body'> & IncomingMessage & {
|
|
18
|
-
body?: unknown;
|
|
19
|
-
};
|
|
20
7
|
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
|
-
|
|
8
|
+
JSONData extends JsonValue = any, // with default to Dictionary we cant use a typed router in untyped crawler
|
|
9
|
+
ContextExtension = Dictionary<never>> = ErrorHandler<CrawlingContext, HttpCrawlingContext<UserData, JSONData> & ContextExtension>;
|
|
10
|
+
export interface HttpCrawlerOptions<Context extends InternalHttpCrawlingContext = InternalHttpCrawlingContext, ContextExtension = Dictionary<never>, ExtendedContext extends Context = Context & ContextExtension> extends BasicCrawlerOptions<Context, ContextExtension, ExtendedContext> {
|
|
23
11
|
/**
|
|
24
12
|
* Timeout in which the HTTP request to the resource needs to finish, given in seconds.
|
|
25
13
|
*/
|
|
@@ -28,45 +16,45 @@ export interface HttpCrawlerOptions<Context extends InternalHttpCrawlingContext
|
|
|
28
16
|
* If set to true, SSL certificate errors will be ignored.
|
|
29
17
|
*/
|
|
30
18
|
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
19
|
/**
|
|
38
20
|
* 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
|
|
21
|
+
* or browser properties before navigation. The function accepts one parameter `crawlingContext`,
|
|
22
|
+
* which is passed to the `requestAsBrowser()` function the crawler calls to navigate.
|
|
23
|
+
*
|
|
24
|
+
* A hook may optionally return a partial object whose properties are merged into the crawling context,
|
|
25
|
+
* allowing the hook to override context members for subsequent hooks and pipeline stages.
|
|
41
26
|
* Example:
|
|
42
27
|
* ```
|
|
43
28
|
* preNavigationHooks: [
|
|
44
|
-
* async (crawlingContext
|
|
29
|
+
* async (crawlingContext) => {
|
|
45
30
|
* // ...
|
|
46
31
|
* },
|
|
47
32
|
* ]
|
|
48
33
|
* ```
|
|
49
|
-
*
|
|
50
|
-
* Modyfing `pageOptions` is supported only in Playwright incognito.
|
|
51
|
-
* See {@link PrePageCreateHook}
|
|
52
34
|
*/
|
|
53
|
-
preNavigationHooks?: InternalHttpHook<
|
|
35
|
+
preNavigationHooks?: InternalHttpHook<CrawlingContext>[];
|
|
54
36
|
/**
|
|
55
37
|
* Async functions that are sequentially evaluated after the navigation. Good for checking if the navigation was successful.
|
|
56
38
|
* The function accepts `crawlingContext` as the only parameter.
|
|
39
|
+
*
|
|
40
|
+
* A hook may optionally return a partial object whose properties are merged into the crawling context,
|
|
41
|
+
* which is useful for overriding the `response` after solving a challenge or re-fetching the resource.
|
|
57
42
|
* Example:
|
|
58
43
|
* ```
|
|
59
44
|
* postNavigationHooks: [
|
|
60
45
|
* async (crawlingContext) => {
|
|
61
|
-
*
|
|
46
|
+
* if (await needsRevalidation(crawlingContext)) {
|
|
47
|
+
* return { response: await refetch(crawlingContext.request) };
|
|
48
|
+
* }
|
|
62
49
|
* },
|
|
63
50
|
* ]
|
|
64
51
|
* ```
|
|
65
52
|
*/
|
|
66
|
-
postNavigationHooks?:
|
|
53
|
+
postNavigationHooks?: ((crawlingContext: CrawlingContextWithResponse) => Awaitable<void | Partial<CrawlingContextWithResponse>>)[];
|
|
67
54
|
/**
|
|
68
55
|
* 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
|
|
56
|
+
* you want the crawler to load and process. By default, only `text/html`, `application/xhtml+xml`, `text/xml`, `application/xml`,
|
|
57
|
+
* and `application/json` MIME types are supported.
|
|
70
58
|
*/
|
|
71
59
|
additionalMimeTypes?: string[];
|
|
72
60
|
/**
|
|
@@ -92,35 +80,34 @@ export interface HttpCrawlerOptions<Context extends InternalHttpCrawlingContext
|
|
|
92
80
|
*/
|
|
93
81
|
forceResponseEncoding?: string;
|
|
94
82
|
/**
|
|
95
|
-
* Automatically saves cookies to Session.
|
|
83
|
+
* Automatically saves cookies to Session. Enabled by default.
|
|
96
84
|
*
|
|
97
85
|
* It parses cookie from response "set-cookie" header saves or updates cookies for session and once the session is used for next request.
|
|
98
86
|
* It passes the "Cookie" header to the request with the session cookies.
|
|
99
87
|
*/
|
|
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[];
|
|
88
|
+
saveResponseCookies?: boolean;
|
|
111
89
|
}
|
|
112
90
|
/**
|
|
113
91
|
* @internal
|
|
114
92
|
*/
|
|
115
|
-
export type InternalHttpHook<Context> = (crawlingContext: Context
|
|
93
|
+
export type InternalHttpHook<Context> = (crawlingContext: Context) => Awaitable<void | Partial<Context>>;
|
|
116
94
|
export type HttpHook<UserData extends Dictionary = any, // with default to Dictionary we cant use a typed router in untyped crawler
|
|
117
95
|
JSONData extends JsonValue = any> = InternalHttpHook<HttpCrawlingContext<UserData, JSONData>>;
|
|
96
|
+
interface CrawlingContextWithResponse<UserData extends Dictionary = any> extends CrawlingContext<UserData> {
|
|
97
|
+
/**
|
|
98
|
+
* The request object that was successfully loaded and navigated to, including the {@link Request.loadedUrl|`loadedUrl`} property.
|
|
99
|
+
*/
|
|
100
|
+
request: LoadedRequest<CrawleeRequest<UserData>>;
|
|
101
|
+
/**
|
|
102
|
+
* The HTTP response object containing status code, headers, and other response metadata.
|
|
103
|
+
*/
|
|
104
|
+
response: Response;
|
|
105
|
+
}
|
|
118
106
|
/**
|
|
119
107
|
* @internal
|
|
120
108
|
*/
|
|
121
109
|
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> {
|
|
110
|
+
JSONData extends JsonValue = any> extends CrawlingContextWithResponse<UserData> {
|
|
124
111
|
/**
|
|
125
112
|
* The request body of the web page.
|
|
126
113
|
* The type depends on the `Content-Type` header of the web page:
|
|
@@ -139,7 +126,6 @@ Crawler = HttpCrawler<any>> extends CrawlingContext<Crawler, UserData> {
|
|
|
139
126
|
type: string;
|
|
140
127
|
encoding: BufferEncoding;
|
|
141
128
|
};
|
|
142
|
-
response: PlainResponse;
|
|
143
129
|
/**
|
|
144
130
|
* Wait for an element matching the selector to appear. Timeout is ignored.
|
|
145
131
|
*
|
|
@@ -167,7 +153,7 @@ Crawler = HttpCrawler<any>> extends CrawlingContext<Crawler, UserData> {
|
|
|
167
153
|
*/
|
|
168
154
|
parseWithCheerio(selector?: string, timeoutMs?: number): Promise<CheerioRoot>;
|
|
169
155
|
}
|
|
170
|
-
export interface HttpCrawlingContext<UserData extends Dictionary = any, JSONData extends JsonValue = any> extends InternalHttpCrawlingContext<UserData, JSONData
|
|
156
|
+
export interface HttpCrawlingContext<UserData extends Dictionary = any, JSONData extends JsonValue = any> extends InternalHttpCrawlingContext<UserData, JSONData> {
|
|
171
157
|
}
|
|
172
158
|
export type HttpRequestHandler<UserData extends Dictionary = any, // with default to Dictionary we cant use a typed router in untyped crawler
|
|
173
159
|
JSONData extends JsonValue = any> = RequestHandler<HttpCrawlingContext<UserData, JSONData>>;
|
|
@@ -182,28 +168,30 @@ JSONData extends JsonValue = any> = RequestHandler<HttpCrawlingContext<UserData,
|
|
|
182
168
|
*
|
|
183
169
|
* This crawler downloads each URL using a plain HTTP request and doesn't do any HTML parsing.
|
|
184
170
|
*
|
|
185
|
-
* The source URLs are represented using {@link Request} objects that are fed from
|
|
186
|
-
* {@link
|
|
187
|
-
*
|
|
171
|
+
* The source URLs are represented using {@link Request} objects that are fed from the
|
|
172
|
+
* {@link IRequestManager|request manager} provided via the {@link HttpCrawlerOptions.requestManager|`requestManager`}
|
|
173
|
+
* constructor option (a {@link RequestQueue} is itself a request manager). To read from a read-only source such
|
|
174
|
+
* as a {@link RequestList} while still being able to enqueue new requests, combine it with a queue into a
|
|
175
|
+
* {@link RequestManagerTandem} via {@link IRequestLoader.toTandem|`requestLoader.toTandem()`} and pass the
|
|
176
|
+
* result as `requestManager`.
|
|
188
177
|
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
* to {@link RequestQueue} before it starts their processing. This ensures that a single URL is not crawled multiple times.
|
|
178
|
+
* > The {@link HttpCrawlerOptions.requestList|`requestList`} and {@link HttpCrawlerOptions.requestQueue|`requestQueue`}
|
|
179
|
+
* > options are deprecated; they are still accepted and folded into a single `requestManager` for back-compat.
|
|
192
180
|
*
|
|
193
181
|
* The crawler finishes when there are no more {@link Request} objects to crawl.
|
|
194
182
|
*
|
|
195
|
-
* We can use the `preNavigationHooks` to adjust
|
|
183
|
+
* We can use the `preNavigationHooks` to adjust the crawling context before the request is made:
|
|
196
184
|
*
|
|
197
185
|
* ```javascript
|
|
198
186
|
* preNavigationHooks: [
|
|
199
|
-
* (crawlingContext
|
|
187
|
+
* (crawlingContext) => {
|
|
200
188
|
* // ...
|
|
201
189
|
* },
|
|
202
190
|
* ]
|
|
203
191
|
* ```
|
|
204
192
|
*
|
|
205
|
-
* By default, this crawler only processes web pages with the `text/html`
|
|
206
|
-
* and `application/
|
|
193
|
+
* By default, this crawler only processes web pages with the `text/html`, `application/xhtml+xml`, `text/xml`, `application/xml`,
|
|
194
|
+
* and `application/json` MIME content types (as reported by the `Content-Type` HTTP header),
|
|
207
195
|
* and skips pages with other content types. If you want the crawler to process other content types,
|
|
208
196
|
* use the {@link HttpCrawlerOptions.additionalMimeTypes} constructor option.
|
|
209
197
|
* Beware that the parsing behavior differs for HTML, XML, JSON and other types of content.
|
|
@@ -238,24 +226,15 @@ JSONData extends JsonValue = any> = RequestHandler<HttpCrawlingContext<UserData,
|
|
|
238
226
|
* ```
|
|
239
227
|
* @category Crawlers
|
|
240
228
|
*/
|
|
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>;
|
|
229
|
+
export declare class HttpCrawler<Context extends InternalHttpCrawlingContext<any, any> = InternalHttpCrawlingContext, ContextExtension = Dictionary<never>, ExtendedContext extends Context = Context & ContextExtension> extends BasicCrawler<Context, ContextExtension, ExtendedContext> {
|
|
230
|
+
private preNavigationHooks;
|
|
231
|
+
private postNavigationHooks;
|
|
232
|
+
private saveResponseCookies;
|
|
233
|
+
private navigationTimeoutMillis;
|
|
234
|
+
private ignoreSslErrors;
|
|
235
|
+
private suggestResponseEncoding?;
|
|
236
|
+
private forceResponseEncoding?;
|
|
237
|
+
private readonly supportedMimeTypes;
|
|
259
238
|
protected static optionsShape: {
|
|
260
239
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
261
240
|
navigationTimeoutSecs: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
@@ -268,17 +247,15 @@ export declare class HttpCrawler<Context extends InternalHttpCrawlingContext<any
|
|
|
268
247
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
269
248
|
forceResponseEncoding: import("ow").StringPredicate & import("ow").BasePredicate<string | undefined>;
|
|
270
249
|
// @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>;
|
|
250
|
+
saveResponseCookies: import("ow").BooleanPredicate & import("ow").BasePredicate<boolean | undefined>;
|
|
278
251
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
279
252
|
preNavigationHooks: import("ow").ArrayPredicate<unknown> & import("ow").BasePredicate<unknown[] | undefined>;
|
|
280
253
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
281
254
|
postNavigationHooks: import("ow").ArrayPredicate<unknown> & import("ow").BasePredicate<unknown[] | undefined>;
|
|
255
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
256
|
+
contextPipelineBuilder: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
257
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
258
|
+
extendContext: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
|
|
282
259
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
283
260
|
requestList: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
284
261
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
@@ -295,28 +272,42 @@ export declare class HttpCrawler<Context extends InternalHttpCrawlingContext<any
|
|
|
295
272
|
maxRequestRetries: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
296
273
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
297
274
|
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
275
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
301
276
|
maxRequestsPerCrawl: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
277
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
278
|
+
maxCrawlDepth: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
302
279
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
303
280
|
autoscaledPoolOptions: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
304
281
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
305
|
-
|
|
282
|
+
sessionPool: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
306
283
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
307
|
-
|
|
284
|
+
proxyConfiguration: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
308
285
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
309
286
|
statusMessageLoggingInterval: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
310
287
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
311
288
|
statusMessageCallback: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
|
|
289
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
290
|
+
additionalHttpErrorStatusCodes: import("ow").ArrayPredicate<number>;
|
|
291
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
292
|
+
ignoreHttpErrorStatusCodes: import("ow").ArrayPredicate<number>;
|
|
293
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
294
|
+
blockedStatusCodes: import("ow").ArrayPredicate<number>;
|
|
312
295
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
313
296
|
retryOnBlocked: import("ow").BooleanPredicate & import("ow").BasePredicate<boolean | undefined>;
|
|
314
297
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
315
|
-
respectRobotsTxtFile: import("ow").
|
|
298
|
+
respectRobotsTxtFile: import("ow").AnyPredicate<boolean | object>;
|
|
316
299
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
317
300
|
onSkippedRequest: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
|
|
318
301
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
319
302
|
httpClient: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
303
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
304
|
+
configuration: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
305
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
306
|
+
storageBackend: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
307
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
308
|
+
eventManager: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
309
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
310
|
+
logger: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
320
311
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
321
312
|
minConcurrency: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
322
313
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
@@ -325,162 +316,50 @@ export declare class HttpCrawler<Context extends InternalHttpCrawlingContext<any
|
|
|
325
316
|
maxRequestsPerMinute: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
326
317
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
327
318
|
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
319
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
333
320
|
statisticsOptions: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
321
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
322
|
+
id: import("ow").StringPredicate & import("ow").BasePredicate<string | undefined>;
|
|
334
323
|
};
|
|
335
324
|
/**
|
|
336
325
|
* All `HttpCrawlerOptions` parameters are passed via an options object.
|
|
337
326
|
*/
|
|
338
|
-
constructor(options?: HttpCrawlerOptions<Context
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
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>;
|
|
351
|
-
/**
|
|
352
|
-
* Sets the cookie header to `gotOptions` based on the provided request and session headers, as well as any changes that occurred due to hooks.
|
|
353
|
-
*/
|
|
354
|
-
protected _applyCookies({ session, request }: CrawlingContext, gotOptions: OptionsInit, preHookCookies: string, postHookCookies: string): void;
|
|
327
|
+
constructor(options?: HttpCrawlerOptions<Context, ContextExtension, ExtendedContext> & RequireContextPipeline<InternalHttpCrawlingContext, Context>);
|
|
328
|
+
protected buildContextPipeline(): ContextPipeline<CrawlingContext, InternalHttpCrawlingContext>;
|
|
329
|
+
private prepareHttpRequest;
|
|
330
|
+
private makeHttpRequest;
|
|
331
|
+
private processHttpResponse;
|
|
332
|
+
private handleBlockedRequestByContent;
|
|
333
|
+
protected isRequestBlocked(crawlingContext: InternalHttpCrawlingContext): Promise<string | false>;
|
|
355
334
|
/**
|
|
356
335
|
* Function to make the HTTP request. It performs optimizations
|
|
357
336
|
* on the request such as only downloading the request body if the
|
|
358
337
|
* received content type matches text/html, application/xml, application/xhtml+xml.
|
|
359
338
|
*/
|
|
360
|
-
|
|
339
|
+
private requestFunction;
|
|
361
340
|
/**
|
|
362
341
|
* Encodes and parses response according to the provided content type
|
|
363
342
|
*/
|
|
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>>;
|
|
343
|
+
private parseResponse;
|
|
384
344
|
/**
|
|
385
345
|
* Combines the provided `requestOptions` with mandatory (non-overridable) values.
|
|
386
346
|
*/
|
|
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
|
-
};
|
|
347
|
+
private getRequestOptions;
|
|
348
|
+
private encodeResponse;
|
|
464
349
|
/**
|
|
465
350
|
* Checks and extends supported mime types
|
|
466
351
|
*/
|
|
467
|
-
|
|
352
|
+
private extendSupportedMimeTypes;
|
|
468
353
|
/**
|
|
469
354
|
* Handles timeout request
|
|
470
355
|
*/
|
|
471
|
-
|
|
356
|
+
private handleRequestTimeout;
|
|
472
357
|
private _abortDownloadOfBody;
|
|
473
358
|
/**
|
|
474
359
|
* @internal wraps public utility for mocking purposes
|
|
475
360
|
*/
|
|
476
361
|
private _requestAsBrowser;
|
|
477
362
|
}
|
|
478
|
-
interface RequestFunctionOptions {
|
|
479
|
-
request: Request;
|
|
480
|
-
session?: Session;
|
|
481
|
-
proxyUrl?: string;
|
|
482
|
-
gotOptions: OptionsInit;
|
|
483
|
-
}
|
|
484
363
|
/**
|
|
485
364
|
* Creates new {@link Router} instance that works based on request labels.
|
|
486
365
|
* This instance can then serve as a `requestHandler` of your {@link HttpCrawler}.
|
|
@@ -505,7 +384,7 @@ interface RequestFunctionOptions {
|
|
|
505
384
|
* await crawler.run();
|
|
506
385
|
* ```
|
|
507
386
|
*/
|
|
508
|
-
|
|
509
|
-
export declare function createHttpRouter<Context extends HttpCrawlingContext = HttpCrawlingContext, UserData extends Dictionary = GetUserDataFromRequest<Context['request']>>(routes?: RouterRoutes<Context, UserData
|
|
387
|
+
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>;
|
|
388
|
+
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>>;
|
|
389
|
+
export declare function createHttpRouter<Context extends HttpCrawlingContext = HttpCrawlingContext, const Schemas extends RouteSchemas = RouteSchemas>(schemas: Schemas): RouterHandler<Context, RoutesFromSchemas<Schemas>>;
|
|
510
390
|
export {};
|
|
511
|
-
//# sourceMappingURL=http-crawler.d.ts.map
|