@crawlee/cheerio 3.0.0-beta.8 → 3.0.1-beta.0
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 +75 -133
- package/index.mjs +8 -0
- package/internals/cheerio-crawler.d.ts +92 -185
- package/internals/cheerio-crawler.d.ts.map +1 -1
- package/internals/cheerio-crawler.js +62 -24
- package/internals/cheerio-crawler.js.map +1 -1
- package/package.json +15 -11
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -1,144 +1,81 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
export declare type CheerioFailedRequestHandler<JSONData = Dictionary> = (inputs:
|
|
13
|
-
export interface CheerioCrawlerOptions<JSONData = Dictionary> extends Omit<BasicCrawlerOptions<CheerioCrawlingContext<JSONData>>, 'requestHandler' | 'handleRequestFunction' | 'failedRequestHandler' | 'handleFailedRequestFunction' | 'handleRequestTimeoutSecs'> {
|
|
3
|
+
import type { BasicCrawlerOptions } from '@crawlee/basic';
|
|
4
|
+
import { BasicCrawler } from '@crawlee/basic';
|
|
5
|
+
import type { CrawlingContext, EnqueueLinksOptions, ProxyConfiguration, Request, RequestQueue, Session } from '@crawlee/core';
|
|
6
|
+
import { CrawlerExtension } from '@crawlee/core';
|
|
7
|
+
import type { BatchAddRequestsResult, Awaitable, Dictionary } from '@crawlee/types';
|
|
8
|
+
import type { CheerioRoot } from '@crawlee/utils';
|
|
9
|
+
import type { RequestLike, ResponseLike } from 'content-type';
|
|
10
|
+
import type { OptionsInit, Response as GotResponse, GotOptionsInit } from 'got-scraping';
|
|
11
|
+
import type { IncomingMessage } from 'http';
|
|
12
|
+
export declare type CheerioFailedRequestHandler<JSONData = Dictionary> = (inputs: CheerioCrawlingContext<JSONData>, error: Error) => Awaitable<void>;
|
|
13
|
+
export interface CheerioCrawlerOptions<JSONData = Dictionary> extends Omit<BasicCrawlerOptions<CheerioCrawlingContext<JSONData>>, 'requestHandler' | 'handleRequestFunction' | 'failedRequestHandler' | 'handleFailedRequestFunction' | 'handleRequestTimeoutSecs' | 'errorHandler'> {
|
|
14
14
|
/**
|
|
15
15
|
* User-provided function that performs the logic of the crawler. It is called for each page
|
|
16
16
|
* loaded and parsed by the crawler.
|
|
17
17
|
*
|
|
18
|
-
* The function receives the
|
|
19
|
-
*
|
|
20
|
-
* {
|
|
21
|
-
* // The Cheerio object's function with the parsed HTML.
|
|
22
|
-
* $: Cheerio,
|
|
23
|
-
*
|
|
24
|
-
* // The request body of the web page, whose type depends on the content type.
|
|
25
|
-
* body: String|Buffer,
|
|
26
|
-
*
|
|
27
|
-
* // The parsed object from JSON for responses with the "application/json" content types.
|
|
28
|
-
* // For other content types it's null.
|
|
29
|
-
* json: Object,
|
|
30
|
-
*
|
|
31
|
-
* // Request object with details of the requested web page
|
|
32
|
-
* request: Request,
|
|
33
|
-
*
|
|
34
|
-
* // Parsed Content-Type HTTP header: { type, encoding }
|
|
35
|
-
* contentType: Object,
|
|
36
|
-
*
|
|
37
|
-
* // An instance of Node's http.IncomingMessage object,
|
|
38
|
-
* response: Object,
|
|
39
|
-
*
|
|
40
|
-
* // Session object, useful to work around anti-scraping protections
|
|
41
|
-
* session: Session
|
|
42
|
-
*
|
|
43
|
-
* // ProxyInfo object with information about currently used proxy
|
|
44
|
-
* proxyInfo: ProxyInfo
|
|
18
|
+
* The function receives the {@link CheerioCrawlingContext} as an argument,
|
|
19
|
+
* where the {@link CheerioCrawlingContext.request} instance represents the URL to crawl.
|
|
45
20
|
*
|
|
46
|
-
*
|
|
47
|
-
* crawler: CheerioCrawler
|
|
48
|
-
* }
|
|
49
|
-
* ```
|
|
50
|
-
*
|
|
51
|
-
* Type of `body` depends on the `Content-Type` header of the web page:
|
|
21
|
+
* Type of {@link CheerioCrawlingContext.body} depends on the `Content-Type` header of the web page:
|
|
52
22
|
* - String for `text/html`, `application/xhtml+xml`, `application/xml` MIME content types
|
|
53
23
|
* - Buffer for others MIME content types
|
|
54
24
|
*
|
|
55
25
|
* Parsed `Content-Type` header using
|
|
56
26
|
* [content-type package](https://www.npmjs.com/package/content-type)
|
|
57
|
-
* is stored in
|
|
27
|
+
* is stored in {@link CheerioCrawlingContext.contentType}`.
|
|
58
28
|
*
|
|
59
29
|
* Cheerio is available only for HTML and XML content types.
|
|
60
30
|
*
|
|
61
|
-
* With the {@link Request} object representing the URL to crawl.
|
|
62
|
-
*
|
|
63
31
|
* If the function returns, the returned promise is awaited by the crawler.
|
|
64
32
|
*
|
|
65
33
|
* If the function throws an exception, the crawler will try to re-crawl the
|
|
66
34
|
* request later, up to `option.maxRequestRetries` times.
|
|
67
35
|
* If all the retries fail, the crawler calls the function
|
|
68
|
-
* provided to the `
|
|
36
|
+
* provided to the `failedRequestHandler` parameter.
|
|
69
37
|
* To make this work, you should **always**
|
|
70
38
|
* let your function throw exceptions rather than catch them.
|
|
71
39
|
* The exceptions are logged to the request using the
|
|
72
40
|
* {@link Request.pushErrorMessage} function.
|
|
73
41
|
*/
|
|
74
|
-
requestHandler
|
|
42
|
+
requestHandler?: CheerioRequestHandler<JSONData>;
|
|
75
43
|
/**
|
|
76
44
|
* User-provided function that performs the logic of the crawler. It is called for each page
|
|
77
45
|
* loaded and parsed by the crawler.
|
|
78
46
|
*
|
|
79
|
-
* The function receives the
|
|
80
|
-
*
|
|
81
|
-
* {
|
|
82
|
-
* // The Cheerio object's function with the parsed HTML.
|
|
83
|
-
* $: Cheerio,
|
|
84
|
-
*
|
|
85
|
-
* // The request body of the web page, whose type depends on the content type.
|
|
86
|
-
* body: String|Buffer,
|
|
87
|
-
*
|
|
88
|
-
* // The parsed object from JSON for responses with the "application/json" content types.
|
|
89
|
-
* // For other content types it's null.
|
|
90
|
-
* json: Object,
|
|
91
|
-
*
|
|
92
|
-
* // Request object with details of the requested web page
|
|
93
|
-
* request: Request,
|
|
94
|
-
*
|
|
95
|
-
* // Parsed Content-Type HTTP header: { type, encoding }
|
|
96
|
-
* contentType: Object,
|
|
47
|
+
* The function receives the {@link CheerioCrawlingContext} as an argument,
|
|
48
|
+
* where the {@link CheerioCrawlingContext.request} instance represents the URL to crawl.
|
|
97
49
|
*
|
|
98
|
-
*
|
|
99
|
-
* response: Object,
|
|
100
|
-
*
|
|
101
|
-
* // Session object, useful to work around anti-scraping protections
|
|
102
|
-
* session: Session
|
|
103
|
-
*
|
|
104
|
-
* // ProxyInfo object with information about currently used proxy
|
|
105
|
-
* proxyInfo: ProxyInfo
|
|
106
|
-
*
|
|
107
|
-
* // The running cheerio crawler instance.
|
|
108
|
-
* crawler: CheerioCrawler
|
|
109
|
-
* }
|
|
110
|
-
* ```
|
|
111
|
-
*
|
|
112
|
-
* Type of `body` depends on the `Content-Type` header of the web page:
|
|
50
|
+
* Type of {@link CheerioCrawlingContext.body} depends on the `Content-Type` header of the web page:
|
|
113
51
|
* - String for `text/html`, `application/xhtml+xml`, `application/xml` MIME content types
|
|
114
52
|
* - Buffer for others MIME content types
|
|
115
53
|
*
|
|
116
54
|
* Parsed `Content-Type` header using
|
|
117
55
|
* [content-type package](https://www.npmjs.com/package/content-type)
|
|
118
|
-
* is stored in
|
|
56
|
+
* is stored in {@link CheerioCrawlingContext.contentType}`.
|
|
119
57
|
*
|
|
120
58
|
* Cheerio is available only for HTML and XML content types.
|
|
121
59
|
*
|
|
122
|
-
* With the {@link Request} object representing the URL to crawl.
|
|
123
|
-
*
|
|
124
60
|
* If the function returns, the returned promise is awaited by the crawler.
|
|
125
61
|
*
|
|
126
62
|
* If the function throws an exception, the crawler will try to re-crawl the
|
|
127
63
|
* request later, up to `option.maxRequestRetries` times.
|
|
128
64
|
* If all the retries fail, the crawler calls the function
|
|
129
|
-
* provided to the `
|
|
65
|
+
* provided to the `failedRequestHandler` parameter.
|
|
130
66
|
* To make this work, you should **always**
|
|
131
67
|
* let your function throw exceptions rather than catch them.
|
|
132
68
|
* The exceptions are logged to the request using the
|
|
133
69
|
* {@link Request.pushErrorMessage} function.
|
|
134
70
|
*
|
|
135
71
|
* @deprecated `handlePageFunction` has been renamed to `requestHandler` and will be removed in a future version.
|
|
72
|
+
* @ignore
|
|
136
73
|
*/
|
|
137
74
|
handlePageFunction?: CheerioRequestHandler<JSONData>;
|
|
138
75
|
/**
|
|
139
76
|
* Timeout in which the HTTP request to the resource needs to finish, given in seconds.
|
|
140
77
|
*/
|
|
141
|
-
|
|
78
|
+
navigationTimeoutSecs?: number;
|
|
142
79
|
/**
|
|
143
80
|
* If set to true, SSL certificate errors will be ignored.
|
|
144
81
|
*/
|
|
@@ -149,54 +86,41 @@ export interface CheerioCrawlerOptions<JSONData = Dictionary> extends Omit<Basic
|
|
|
149
86
|
* For more information, see the [documentation](https://docs.apify.com/proxy).
|
|
150
87
|
*/
|
|
151
88
|
proxyConfiguration?: ProxyConfiguration;
|
|
89
|
+
/**
|
|
90
|
+
* User-provided function that allows modifying the request object before it gets retried by the crawler.
|
|
91
|
+
* It's executed before each retry for the requests that failed less than `option.maxRequestRetries` times.
|
|
92
|
+
*
|
|
93
|
+
* The function receives the {@link CheerioCrawlingContext} as the first argument,
|
|
94
|
+
* where the {@link CheerioCrawlingContext.request} corresponds to the request to be retried.
|
|
95
|
+
* Second argument is the `Error` instance that
|
|
96
|
+
* represents the last error thrown during processing of the request.
|
|
97
|
+
*/
|
|
98
|
+
errorHandler?: CheerioFailedRequestHandler<JSONData>;
|
|
152
99
|
/**
|
|
153
100
|
* A function to handle requests that failed more than `option.maxRequestRetries` times.
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
* {
|
|
157
|
-
*
|
|
158
|
-
* request: Request,
|
|
159
|
-
* session: Session,
|
|
160
|
-
* $: Cheerio,
|
|
161
|
-
* body: String|Buffer,
|
|
162
|
-
* json: Object,
|
|
163
|
-
* contentType: Object,
|
|
164
|
-
* response: Object,
|
|
165
|
-
* proxyInfo: ProxyInfo,
|
|
166
|
-
* crawler: CheerioCrawler,
|
|
167
|
-
* }
|
|
168
|
-
* ```
|
|
169
|
-
* where the {@link Request} instance corresponds to the failed request, and the `Error` instance
|
|
101
|
+
*
|
|
102
|
+
* The function receives the {@link CheerioCrawlingContext} as the first argument,
|
|
103
|
+
* where the {@link CheerioCrawlingContext.request} corresponds to the failed request.
|
|
104
|
+
* Second argument is the `Error` instance that
|
|
170
105
|
* represents the last error thrown during processing of the request.
|
|
171
106
|
*
|
|
172
|
-
* See [source code](https://github.com/apify/
|
|
107
|
+
* See [source code](https://github.com/apify/crawlee/blob/master/src/crawlers/cheerio_crawler.js#L13)
|
|
173
108
|
* for the default implementation of this function.
|
|
174
109
|
*/
|
|
175
110
|
failedRequestHandler?: CheerioFailedRequestHandler<JSONData>;
|
|
176
111
|
/**
|
|
177
112
|
* A function to handle requests that failed more than `option.maxRequestRetries` times.
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
* {
|
|
181
|
-
*
|
|
182
|
-
* request: Request,
|
|
183
|
-
* session: Session,
|
|
184
|
-
* $: Cheerio,
|
|
185
|
-
* body: String|Buffer,
|
|
186
|
-
* json: Object,
|
|
187
|
-
* contentType: Object,
|
|
188
|
-
* response: Object,
|
|
189
|
-
* proxyInfo: ProxyInfo,
|
|
190
|
-
* crawler: CheerioCrawler,
|
|
191
|
-
* }
|
|
192
|
-
* ```
|
|
193
|
-
* where the {@link Request} instance corresponds to the failed request, and the `Error` instance
|
|
113
|
+
*
|
|
114
|
+
* The function receives the {@link CheerioCrawlingContext} as the first argument,
|
|
115
|
+
* where the {@link CheerioCrawlingContext.request} corresponds to the failed request.
|
|
116
|
+
* Second argument is the `Error` instance that
|
|
194
117
|
* represents the last error thrown during processing of the request.
|
|
195
118
|
*
|
|
196
|
-
* See [source code](https://github.com/apify/
|
|
119
|
+
* See [source code](https://github.com/apify/crawlee/blob/master/src/crawlers/cheerio_crawler.js#L13)
|
|
197
120
|
* for the default implementation of this function.
|
|
198
121
|
*
|
|
199
122
|
* @deprecated `handleFailedRequestFunction` has been renamed to `failedRequestHandler` and will be removed in a future version.
|
|
123
|
+
* @ignore
|
|
200
124
|
*/
|
|
201
125
|
handleFailedRequestFunction?: CheerioFailedRequestHandler<JSONData>;
|
|
202
126
|
/**
|
|
@@ -261,46 +185,8 @@ export interface CheerioCrawlerOptions<JSONData = Dictionary> extends Omit<Basic
|
|
|
261
185
|
*/
|
|
262
186
|
persistCookiesPerSession?: boolean;
|
|
263
187
|
}
|
|
264
|
-
export interface PrepareRequestInputs<JSONData = Dictionary> {
|
|
265
|
-
/**
|
|
266
|
-
* Original instance of the {@link Request} object. Must be modified in-place.
|
|
267
|
-
*/
|
|
268
|
-
request: Request;
|
|
269
|
-
/**
|
|
270
|
-
* The current session
|
|
271
|
-
*/
|
|
272
|
-
session?: Session;
|
|
273
|
-
/**
|
|
274
|
-
* An object with information about currently used proxy by the crawler
|
|
275
|
-
* and configured by the {@link ProxyConfiguration} class.
|
|
276
|
-
*/
|
|
277
|
-
proxyInfo?: ProxyInfo;
|
|
278
|
-
crawler?: CheerioCrawler<JSONData>;
|
|
279
|
-
}
|
|
280
|
-
export declare type PrepareRequest<JSONData = Dictionary> = (inputs: PrepareRequestInputs<JSONData>) => Awaitable<void>;
|
|
281
188
|
export declare type CheerioHook<JSONData = Dictionary> = (crawlingContext: CheerioCrawlingContext<JSONData>, gotOptions: OptionsInit) => Awaitable<void>;
|
|
282
|
-
export interface
|
|
283
|
-
/**
|
|
284
|
-
* stream
|
|
285
|
-
*/
|
|
286
|
-
response?: IncomingMessage;
|
|
287
|
-
/**
|
|
288
|
-
* Original instance fo the {Request} object. Must be modified in-place.
|
|
289
|
-
*/
|
|
290
|
-
request: Request;
|
|
291
|
-
/**
|
|
292
|
-
* The current session
|
|
293
|
-
*/
|
|
294
|
-
session?: Session;
|
|
295
|
-
/**
|
|
296
|
-
* An object with information about currently used proxy by the crawler
|
|
297
|
-
* and configured by the {@link ProxyConfiguration} class.
|
|
298
|
-
*/
|
|
299
|
-
proxyInfo?: ProxyInfo;
|
|
300
|
-
crawler: CheerioCrawler<JSONData>;
|
|
301
|
-
}
|
|
302
|
-
export declare type PostResponse<JSONData = Dictionary> = (inputs: PostResponseInputs<JSONData>) => Awaitable<void>;
|
|
303
|
-
export interface CheerioRequestHandlerInputs<JSONData = Dictionary> extends CrawlingContext {
|
|
189
|
+
export interface CheerioCrawlingContext<JSONData extends Dictionary = Dictionary> extends CrawlingContext<JSONData> {
|
|
304
190
|
/**
|
|
305
191
|
* The [Cheerio](https://cheerio.js.org/) object with parsed HTML.
|
|
306
192
|
*/
|
|
@@ -320,12 +206,12 @@ export interface CheerioRequestHandlerInputs<JSONData = Dictionary> extends Craw
|
|
|
320
206
|
type: string;
|
|
321
207
|
encoding: string;
|
|
322
208
|
};
|
|
323
|
-
crawler: CheerioCrawler
|
|
209
|
+
crawler: CheerioCrawler;
|
|
324
210
|
response: IncomingMessage;
|
|
325
211
|
enqueueLinks: (options?: CheerioCrawlerEnqueueLinksOptions) => Promise<BatchAddRequestsResult>;
|
|
212
|
+
sendRequest: (overrideOptions?: Partial<GotOptionsInit>) => Promise<GotResponse<string>>;
|
|
326
213
|
}
|
|
327
|
-
export declare type
|
|
328
|
-
export declare type CheerioRequestHandler<JSONData = Dictionary> = (inputs: CheerioRequestHandlerInputs<JSONData>) => Awaitable<void>;
|
|
214
|
+
export declare type CheerioRequestHandler<JSONData = Dictionary> = (inputs: CheerioCrawlingContext<JSONData>) => Awaitable<void>;
|
|
329
215
|
export declare type CheerioCrawlerEnqueueLinksOptions = Omit<EnqueueLinksOptions, 'urls' | 'requestQueue'>;
|
|
330
216
|
/**
|
|
331
217
|
* Provides a framework for the parallel crawling of web pages using plain HTTP requests and
|
|
@@ -380,18 +266,15 @@ export declare type CheerioCrawlerEnqueueLinksOptions = Omit<EnqueueLinksOptions
|
|
|
380
266
|
*
|
|
381
267
|
* ```javascript
|
|
382
268
|
* // Prepare a list of URLs to crawl
|
|
383
|
-
* const requestList =
|
|
384
|
-
*
|
|
385
|
-
*
|
|
386
|
-
*
|
|
387
|
-
* ],
|
|
388
|
-
* });
|
|
389
|
-
* await requestList.initialize();
|
|
269
|
+
* const requestList = await RequestList.open(null, [
|
|
270
|
+
* { url: 'http://www.example.com/page-1' },
|
|
271
|
+
* { url: 'http://www.example.com/page-2' },
|
|
272
|
+
* ]);
|
|
390
273
|
*
|
|
391
274
|
* // Crawl the URLs
|
|
392
275
|
* const crawler = new CheerioCrawler({
|
|
393
276
|
* requestList,
|
|
394
|
-
*
|
|
277
|
+
* async requestHandler({ request, response, body, contentType, $ }) {
|
|
395
278
|
* const data = [];
|
|
396
279
|
*
|
|
397
280
|
* // Do some data extraction from the page with Cheerio.
|
|
@@ -400,7 +283,7 @@ export declare type CheerioCrawlerEnqueueLinksOptions = Omit<EnqueueLinksOptions
|
|
|
400
283
|
* });
|
|
401
284
|
*
|
|
402
285
|
* // Save the data to dataset.
|
|
403
|
-
* await
|
|
286
|
+
* await Dataset.pushData({
|
|
404
287
|
* url: request.url,
|
|
405
288
|
* html: body,
|
|
406
289
|
* data,
|
|
@@ -412,24 +295,24 @@ export declare type CheerioCrawlerEnqueueLinksOptions = Omit<EnqueueLinksOptions
|
|
|
412
295
|
* ```
|
|
413
296
|
* @category Crawlers
|
|
414
297
|
*/
|
|
415
|
-
export declare class CheerioCrawler
|
|
298
|
+
export declare class CheerioCrawler extends BasicCrawler<CheerioCrawlingContext> {
|
|
416
299
|
/**
|
|
417
300
|
* A reference to the underlying {@link ProxyConfiguration} class that manages the crawler's proxies.
|
|
418
301
|
* Only available if used by the crawler.
|
|
419
302
|
*/
|
|
420
303
|
proxyConfiguration?: ProxyConfiguration;
|
|
421
304
|
protected userRequestHandlerTimeoutMillis: number;
|
|
422
|
-
protected preNavigationHooks: CheerioHook
|
|
423
|
-
protected postNavigationHooks: CheerioHook
|
|
305
|
+
protected preNavigationHooks: CheerioHook[];
|
|
306
|
+
protected postNavigationHooks: CheerioHook[];
|
|
424
307
|
protected persistCookiesPerSession: boolean;
|
|
425
|
-
protected
|
|
308
|
+
protected navigationTimeoutMillis: number;
|
|
426
309
|
protected ignoreSslErrors: boolean;
|
|
427
310
|
protected suggestResponseEncoding?: string;
|
|
428
311
|
protected forceResponseEncoding?: string;
|
|
429
312
|
protected readonly supportedMimeTypes: Set<string>;
|
|
430
313
|
protected static optionsShape: {
|
|
431
314
|
handlePageFunction: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
|
|
432
|
-
|
|
315
|
+
navigationTimeoutSecs: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
433
316
|
ignoreSslErrors: import("ow").BooleanPredicate & import("ow").BasePredicate<boolean | undefined>;
|
|
434
317
|
additionalMimeTypes: import("ow").ArrayPredicate<string>;
|
|
435
318
|
suggestResponseEncoding: import("ow").StringPredicate & import("ow").BasePredicate<string | undefined>;
|
|
@@ -442,11 +325,9 @@ export declare class CheerioCrawler<JSONData = Dictionary> extends BasicCrawler<
|
|
|
442
325
|
requestQueue: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
443
326
|
requestHandler: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
|
|
444
327
|
handleRequestFunction: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
|
|
445
|
-
requestHandlerTimeoutSecs: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
446
|
-
* An object with information about currently used proxy by the crawler
|
|
447
|
-
* and configured by the {@link ProxyConfiguration} class.
|
|
448
|
-
*/
|
|
328
|
+
requestHandlerTimeoutSecs: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
449
329
|
handleRequestTimeoutSecs: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
330
|
+
errorHandler: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
|
|
450
331
|
failedRequestHandler: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
|
|
451
332
|
handleFailedRequestFunction: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
|
|
452
333
|
maxRequestRetries: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
@@ -456,12 +337,13 @@ export declare class CheerioCrawler<JSONData = Dictionary> extends BasicCrawler<
|
|
|
456
337
|
useSessionPool: import("ow").BooleanPredicate & import("ow").BasePredicate<boolean | undefined>;
|
|
457
338
|
minConcurrency: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
458
339
|
maxConcurrency: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
340
|
+
maxRequestsPerMinute: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
459
341
|
log: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
460
342
|
};
|
|
461
343
|
/**
|
|
462
344
|
* All `CheerioCrawler` parameters are passed via an options object.
|
|
463
345
|
*/
|
|
464
|
-
constructor(options
|
|
346
|
+
constructor(options?: CheerioCrawlerOptions);
|
|
465
347
|
/**
|
|
466
348
|
* **EXPERIMENTAL**
|
|
467
349
|
* Function for attaching CrawlerExtensions such as the Unblockers.
|
|
@@ -469,10 +351,10 @@ export declare class CheerioCrawler<JSONData = Dictionary> extends BasicCrawler<
|
|
|
469
351
|
*/
|
|
470
352
|
use(extension: CrawlerExtension): void;
|
|
471
353
|
/**
|
|
472
|
-
* Wrapper around
|
|
354
|
+
* Wrapper around requestHandler that opens and closes pages etc.
|
|
473
355
|
*/
|
|
474
|
-
protected _runRequestHandler(crawlingContext: CheerioCrawlingContext
|
|
475
|
-
protected _handleNavigation(crawlingContext: CheerioCrawlingContext
|
|
356
|
+
protected _runRequestHandler(crawlingContext: CheerioCrawlingContext): Promise<void>;
|
|
357
|
+
protected _handleNavigation(crawlingContext: CheerioCrawlingContext): Promise<void>;
|
|
476
358
|
/**
|
|
477
359
|
* Sets the cookie header to `gotOptions` based on the provided request and session headers, as well as any changes that occurred due to hooks.
|
|
478
360
|
*/
|
|
@@ -545,5 +427,30 @@ interface RequestFunctionOptions {
|
|
|
545
427
|
proxyUrl?: string;
|
|
546
428
|
gotOptions: OptionsInit;
|
|
547
429
|
}
|
|
430
|
+
/**
|
|
431
|
+
* Creates new {@link Router} instance that works based on request labels.
|
|
432
|
+
* This instance can then serve as a `requestHandler` of your {@link CheerioCrawler}.
|
|
433
|
+
* Defaults to the {@link CheerioCrawlingContext}.
|
|
434
|
+
*
|
|
435
|
+
* > Serves as a shortcut for using `Router.create<CheerioCrawlingContext>()`.
|
|
436
|
+
*
|
|
437
|
+
* ```ts
|
|
438
|
+
* import { CheerioCrawler, createCheerioRouter } from 'crawlee';
|
|
439
|
+
*
|
|
440
|
+
* const router = createCheerioRouter();
|
|
441
|
+
* router.addHandler('label-a', async (ctx) => {
|
|
442
|
+
* ctx.log.info('...');
|
|
443
|
+
* });
|
|
444
|
+
* router.addDefaultHandler(async (ctx) => {
|
|
445
|
+
* ctx.log.info('...');
|
|
446
|
+
* });
|
|
447
|
+
*
|
|
448
|
+
* const crawler = new CheerioCrawler({
|
|
449
|
+
* requestHandler: router,
|
|
450
|
+
* });
|
|
451
|
+
* await crawler.run();
|
|
452
|
+
* ```
|
|
453
|
+
*/
|
|
454
|
+
export declare function createCheerioRouter<Context extends CheerioCrawlingContext = CheerioCrawlingContext>(): import("@crawlee/basic").RouterHandler<Context>;
|
|
548
455
|
export {};
|
|
549
456
|
//# sourceMappingURL=cheerio-crawler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cheerio-crawler.d.ts","sourceRoot":"","sources":["../../src/internals/cheerio-crawler.ts"],"names":[],"mappings":";;AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"cheerio-crawler.d.ts","sourceRoot":"","sources":["../../src/internals/cheerio-crawler.ts"],"names":[],"mappings":";;AAEA,OAAO,KAA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