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