@crawlee/cheerio 3.0.3-beta.8 → 3.0.4-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 CHANGED
@@ -63,7 +63,7 @@ Additionally, the package provides various helper functions to simplify running
63
63
 
64
64
  ## Quick Start
65
65
 
66
- This short tutorial will set you up to start using Crawlee in a minute or two. If you want to learn more, proceed to the [Getting Started](https://crawlee.dev/docs/guides/getting-started) tutorial that will take you step by step through creating your first scraper.
66
+ This short tutorial will set you up to start using Crawlee in a minute or two. If you want to learn more, proceed to the [Getting Started](https://crawlee.dev/docs/introduction) tutorial that will take you step by step through creating your first scraper.
67
67
 
68
68
  ### Local stand-alone usage
69
69
 
package/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from '@crawlee/basic';
1
+ export * from '@crawlee/http';
2
2
  export * from './internals/cheerio-crawler';
3
3
  //# sourceMappingURL=index.d.ts.map
package/index.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,6BAA6B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,6BAA6B,CAAC"}
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("@crawlee/basic"), exports);
4
+ tslib_1.__exportStar(require("@crawlee/http"), exports);
5
5
  tslib_1.__exportStar(require("./internals/cheerio-crawler"), exports);
6
6
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,yDAA+B;AAC/B,sEAA4C"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,wDAA8B;AAC9B,sEAA4C"}
package/index.mjs CHANGED
@@ -16,6 +16,7 @@ export const EVENT_SESSION_RETIRED = mod.EVENT_SESSION_RETIRED;
16
16
  export const EnqueueStrategy = mod.EnqueueStrategy;
17
17
  export const EventManager = mod.EventManager;
18
18
  export const EventType = mod.EventType;
19
+ export const HttpCrawler = mod.HttpCrawler;
19
20
  export const KeyValueStore = mod.KeyValueStore;
20
21
  export const LocalEventManager = mod.LocalEventManager;
21
22
  export const Log = mod.Log;
@@ -34,6 +35,7 @@ export const REQUESTS_PERSISTENCE_KEY = mod.REQUESTS_PERSISTENCE_KEY;
34
35
  export const Request = mod.Request;
35
36
  export const RequestList = mod.RequestList;
36
37
  export const RequestQueue = mod.RequestQueue;
38
+ export const RetryRequestError = mod.RetryRequestError;
37
39
  export const Router = mod.Router;
38
40
  export const STATE_PERSISTENCE_KEY = mod.STATE_PERSISTENCE_KEY;
39
41
  export const STORAGE_CONSISTENCY_DELAY_MILLIS = mod.STORAGE_CONSISTENCY_DELAY_MILLIS;
@@ -54,6 +56,7 @@ export const cookieStringToToughCookie = mod.cookieStringToToughCookie;
54
56
  export const createBasicRouter = mod.createBasicRouter;
55
57
  export const createCheerioRouter = mod.createCheerioRouter;
56
58
  export const createDeserialize = mod.createDeserialize;
59
+ export const createHttpRouter = mod.createHttpRouter;
57
60
  export const createRequestOptions = mod.createRequestOptions;
58
61
  export const createRequests = mod.createRequests;
59
62
  export const deserializeArray = mod.deserializeArray;
@@ -1,222 +1,27 @@
1
1
  /// <reference types="node" />
2
- /// <reference types="node" />
3
- import type { BasicCrawlerOptions, ErrorHandler, RequestHandler } from '@crawlee/basic';
4
- import { BasicCrawler } from '@crawlee/basic';
5
- import type { CrawlingContext, EnqueueLinksOptions, ProxyConfiguration, Request, RequestQueue, Session } from '@crawlee/core';
6
- import { CrawlerExtension, Configuration } 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';
2
+ import type { HttpCrawlerOptions, InternalHttpCrawlingContext, InternalHttpHook, ErrorHandler, RequestHandler, EnqueueLinksOptions, RequestQueue, Configuration } from '@crawlee/http';
3
+ import { HttpCrawler } from '@crawlee/http';
4
+ import type { BatchAddRequestsResult, Dictionary } from '@crawlee/types';
5
+ import * as cheerio from 'cheerio';
11
6
  import type { IncomingMessage } from 'http';
12
7
  export declare type CheerioErrorHandler<UserData extends Dictionary = any, // with default to Dictionary we cant use a typed router in untyped crawler
13
- JSONData extends Dictionary = Dictionary> = ErrorHandler<CheerioCrawlingContext<UserData, JSONData>>;
8
+ JSONData extends Dictionary = any> = ErrorHandler<CheerioCrawlingContext<UserData, JSONData>>;
14
9
  export interface CheerioCrawlerOptions<UserData extends Dictionary = any, // with default to Dictionary we cant use a typed router in untyped crawler
15
- JSONData extends Dictionary = Dictionary> extends Omit<BasicCrawlerOptions<CheerioCrawlingContext<UserData, JSONData>>, 'requestHandler' | 'handleRequestFunction' | 'failedRequestHandler' | 'handleFailedRequestFunction' | 'handleRequestTimeoutSecs' | 'errorHandler'> {
16
- /**
17
- * User-provided function that performs the logic of the crawler. It is called for each page
18
- * loaded and parsed by the crawler.
19
- *
20
- * The function receives the {@link CheerioCrawlingContext} as an argument,
21
- * where the {@link CheerioCrawlingContext.request} instance represents the URL to crawl.
22
- *
23
- * Type of {@link CheerioCrawlingContext.body} depends on the `Content-Type` header of the web page:
24
- * - String for `text/html`, `application/xhtml+xml`, `application/xml` MIME content types
25
- * - Buffer for others MIME content types
26
- *
27
- * Parsed `Content-Type` header using
28
- * [content-type package](https://www.npmjs.com/package/content-type)
29
- * is stored in {@link CheerioCrawlingContext.contentType}`.
30
- *
31
- * Cheerio is available only for HTML and XML content types.
32
- *
33
- * If the function returns, the returned promise is awaited by the crawler.
34
- *
35
- * If the function throws an exception, the crawler will try to re-crawl the
36
- * request later, up to `option.maxRequestRetries` times.
37
- * If all the retries fail, the crawler calls the function
38
- * provided to the `failedRequestHandler` parameter.
39
- * To make this work, you should **always**
40
- * let your function throw exceptions rather than catch them.
41
- * The exceptions are logged to the request using the
42
- * {@link Request.pushErrorMessage} function.
43
- */
44
- requestHandler?: CheerioRequestHandler<UserData, JSONData>;
45
- /**
46
- * User-provided function that performs the logic of the crawler. It is called for each page
47
- * loaded and parsed by the crawler.
48
- *
49
- * The function receives the {@link CheerioCrawlingContext} as an argument,
50
- * where the {@link CheerioCrawlingContext.request} instance represents the URL to crawl.
51
- *
52
- * Type of {@link CheerioCrawlingContext.body} depends on the `Content-Type` header of the web page:
53
- * - String for `text/html`, `application/xhtml+xml`, `application/xml` MIME content types
54
- * - Buffer for others MIME content types
55
- *
56
- * Parsed `Content-Type` header using
57
- * [content-type package](https://www.npmjs.com/package/content-type)
58
- * is stored in {@link CheerioCrawlingContext.contentType}`.
59
- *
60
- * Cheerio is available only for HTML and XML content types.
61
- *
62
- * If the function returns, the returned promise is awaited by the crawler.
63
- *
64
- * If the function throws an exception, the crawler will try to re-crawl the
65
- * request later, up to `option.maxRequestRetries` times.
66
- * If all the retries fail, the crawler calls the function
67
- * provided to the `failedRequestHandler` parameter.
68
- * To make this work, you should **always**
69
- * let your function throw exceptions rather than catch them.
70
- * The exceptions are logged to the request using the
71
- * {@link Request.pushErrorMessage} function.
72
- *
73
- * @deprecated `handlePageFunction` has been renamed to `requestHandler` and will be removed in a future version.
74
- * @ignore
75
- */
76
- handlePageFunction?: CheerioRequestHandler<UserData, JSONData>;
77
- /**
78
- * Timeout in which the HTTP request to the resource needs to finish, given in seconds.
79
- */
80
- navigationTimeoutSecs?: number;
81
- /**
82
- * If set to true, SSL certificate errors will be ignored.
83
- */
84
- ignoreSslErrors?: boolean;
85
- /**
86
- * If set, `CheerioCrawler` will be configured for all connections to use
87
- * [Apify Proxy](https://console.apify.com/proxy) or your own Proxy URLs provided and rotated according to the configuration.
88
- * For more information, see the [documentation](https://docs.apify.com/proxy).
89
- */
90
- proxyConfiguration?: ProxyConfiguration;
91
- /**
92
- * User-provided function that allows modifying the request object before it gets retried by the crawler.
93
- * It's executed before each retry for the requests that failed less than `option.maxRequestRetries` times.
94
- *
95
- * The function receives the {@link CheerioCrawlingContext} as the first argument,
96
- * where the {@link CheerioCrawlingContext.request} corresponds to the request to be retried.
97
- * Second argument is the `Error` instance that
98
- * represents the last error thrown during processing of the request.
99
- */
100
- errorHandler?: CheerioErrorHandler<UserData, JSONData>;
101
- /**
102
- * A function to handle requests that failed more than `option.maxRequestRetries` times.
103
- *
104
- * The function receives the {@link CheerioCrawlingContext} as the first argument,
105
- * where the {@link CheerioCrawlingContext.request} corresponds to the failed request.
106
- * Second argument is the `Error` instance that
107
- * represents the last error thrown during processing of the request.
108
- *
109
- * See [source code](https://github.com/apify/crawlee/blob/master/src/crawlers/cheerio_crawler.js#L13)
110
- * for the default implementation of this function.
111
- */
112
- failedRequestHandler?: CheerioErrorHandler<UserData, JSONData>;
113
- /**
114
- * A function to handle requests that failed more than `option.maxRequestRetries` times.
115
- *
116
- * The function receives the {@link CheerioCrawlingContext} as the first argument,
117
- * where the {@link CheerioCrawlingContext.request} corresponds to the failed request.
118
- * Second argument is the `Error` instance that
119
- * represents the last error thrown during processing of the request.
120
- *
121
- * See [source code](https://github.com/apify/crawlee/blob/master/src/crawlers/cheerio_crawler.js#L13)
122
- * for the default implementation of this function.
123
- *
124
- * @deprecated `handleFailedRequestFunction` has been renamed to `failedRequestHandler` and will be removed in a future version.
125
- * @ignore
126
- */
127
- handleFailedRequestFunction?: CheerioErrorHandler<UserData, JSONData>;
128
- /**
129
- * Async functions that are sequentially evaluated before the navigation. Good for setting additional cookies
130
- * or browser properties before navigation. The function accepts two parameters, `crawlingContext` and `gotOptions`,
131
- * which are passed to the `requestAsBrowser()` function the crawler calls to navigate.
132
- * Example:
133
- * ```
134
- * preNavigationHooks: [
135
- * async (crawlingContext, gotOptions) => {
136
- * // ...
137
- * },
138
- * ]
139
- * ```
140
- */
141
- preNavigationHooks?: CheerioHook<UserData, JSONData>[];
142
- /**
143
- * Async functions that are sequentially evaluated after the navigation. Good for checking if the navigation was successful.
144
- * The function accepts `crawlingContext` as the only parameter.
145
- * Example:
146
- * ```
147
- * postNavigationHooks: [
148
- * async (crawlingContext) => {
149
- * // ...
150
- * },
151
- * ]
152
- * ```
153
- */
154
- postNavigationHooks?: CheerioHook<UserData, JSONData>[];
155
- /**
156
- * An array of [MIME types](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Complete_list_of_MIME_types)
157
- * you want the crawler to load and process. By default, only `text/html` and `application/xhtml+xml` MIME types are supported.
158
- */
159
- additionalMimeTypes?: string[];
160
- /**
161
- * By default `CheerioCrawler` will extract correct encoding from the HTTP response headers.
162
- * Sadly, there are some websites which use invalid headers. Those are encoded using the UTF-8 encoding.
163
- * If those sites actually use a different encoding, the response will be corrupted. You can use
164
- * `suggestResponseEncoding` to fall back to a certain encoding, if you know that your target website uses it.
165
- * To force a certain encoding, disregarding the response headers, use {@link CheerioCrawlerOptions.forceResponseEncoding}
166
- * ```
167
- * // Will fall back to windows-1250 encoding if none found
168
- * suggestResponseEncoding: 'windows-1250'
169
- * ```
170
- */
171
- suggestResponseEncoding?: string;
172
- /**
173
- * By default `CheerioCrawler` will extract correct encoding from the HTTP response headers. Use `forceResponseEncoding`
174
- * to force a certain encoding, disregarding the response headers.
175
- * To only provide a default for missing encodings, use {@link CheerioCrawlerOptions.suggestResponseEncoding}
176
- * ```
177
- * // Will force windows-1250 encoding even if headers say otherwise
178
- * forceResponseEncoding: 'windows-1250'
179
- * ```
180
- */
181
- forceResponseEncoding?: string;
182
- /**
183
- * Automatically saves cookies to Session. Works only if Session Pool is used.
184
- *
185
- * It parses cookie from response "set-cookie" header saves or updates cookies for session and once the session is used for next request.
186
- * It passes the "Cookie" header to the request with the session cookies.
187
- */
188
- persistCookiesPerSession?: boolean;
10
+ JSONData extends Dictionary = any> extends HttpCrawlerOptions<CheerioCrawlingContext<UserData, JSONData>> {
189
11
  }
190
12
  export declare type CheerioHook<UserData extends Dictionary = any, // with default to Dictionary we cant use a typed router in untyped crawler
191
- JSONData extends Dictionary = Dictionary> = (crawlingContext: CheerioCrawlingContext<UserData, JSONData>, gotOptions: OptionsInit) => Awaitable<void>;
13
+ JSONData extends Dictionary = any> = InternalHttpHook<CheerioCrawlingContext<UserData, JSONData>>;
192
14
  export interface CheerioCrawlingContext<UserData extends Dictionary = any, // with default to Dictionary we cant use a typed router in untyped crawler
193
- JSONData extends Dictionary = Dictionary> extends CrawlingContext<UserData> {
15
+ JSONData extends Dictionary = any> extends InternalHttpCrawlingContext<UserData, JSONData, CheerioCrawler> {
194
16
  /**
195
17
  * The [Cheerio](https://cheerio.js.org/) object with parsed HTML.
18
+ * Cheerio is available only for HTML and XML content types.
196
19
  */
197
- $: CheerioRoot;
198
- /**
199
- * The request body of the web page.
200
- */
201
- body: (string | Buffer);
202
- /**
203
- * The parsed object from JSON string if the response contains the content type application/json.
204
- */
205
- json: JSONData;
206
- /**
207
- * Parsed `Content-Type header: { type, encoding }`.
208
- */
209
- contentType: {
210
- type: string;
211
- encoding: string;
212
- };
213
- crawler: CheerioCrawler;
214
- response: IncomingMessage;
20
+ $: cheerio.CheerioAPI;
215
21
  enqueueLinks: (options?: CheerioCrawlerEnqueueLinksOptions) => Promise<BatchAddRequestsResult>;
216
- sendRequest: (overrideOptions?: Partial<GotOptionsInit>) => Promise<GotResponse<string>>;
217
22
  }
218
23
  export declare type CheerioRequestHandler<UserData extends Dictionary = any, // with default to Dictionary we cant use a typed router in untyped crawler
219
- JSONData extends Dictionary = Dictionary> = RequestHandler<CheerioCrawlingContext<UserData, JSONData>>;
24
+ JSONData extends Dictionary = any> = RequestHandler<CheerioCrawlingContext<UserData, JSONData>>;
220
25
  export interface CheerioCrawlerEnqueueLinksOptions extends Omit<EnqueueLinksOptions, 'urls' | 'requestQueue'> {
221
26
  }
222
27
  /**
@@ -227,23 +32,23 @@ export interface CheerioCrawlerEnqueueLinksOptions extends Omit<EnqueueLinksOpti
227
32
  *
228
33
  * Since `CheerioCrawler` uses raw HTTP requests to download web pages,
229
34
  * it is very fast and efficient on data bandwidth. However, if the target website requires JavaScript
230
- * to display the content, you might need to use {@link PuppeteerCrawler} or {@link PlaywrightCrawler} instead,
35
+ * to display the content, you might need to use {@apilink PuppeteerCrawler} or {@apilink PlaywrightCrawler} instead,
231
36
  * because it loads the pages using full-featured headless Chrome browser.
232
37
  *
233
38
  * `CheerioCrawler` downloads each URL using a plain HTTP request,
234
39
  * parses the HTML content using [Cheerio](https://www.npmjs.com/package/cheerio)
235
- * and then invokes the user-provided {@link CheerioCrawlerOptions.requestHandler} to extract page data
40
+ * and then invokes the user-provided {@apilink CheerioCrawlerOptions.requestHandler} to extract page data
236
41
  * using a [jQuery](https://jquery.com/)-like interface to the parsed HTML DOM.
237
42
  *
238
- * The source URLs are represented using {@link Request} objects that are fed from
239
- * {@link RequestList} or {@link RequestQueue} instances provided by the {@link CheerioCrawlerOptions.requestList}
240
- * or {@link CheerioCrawlerOptions.requestQueue} constructor options, respectively.
43
+ * The source URLs are represented using {@apilink Request} objects that are fed from
44
+ * {@apilink RequestList} or {@apilink RequestQueue} instances provided by the {@apilink CheerioCrawlerOptions.requestList}
45
+ * or {@apilink CheerioCrawlerOptions.requestQueue} constructor options, respectively.
241
46
  *
242
- * If both {@link CheerioCrawlerOptions.requestList} and {@link CheerioCrawlerOptions.requestQueue} are used,
243
- * the instance first processes URLs from the {@link RequestList} and automatically enqueues all of them
244
- * to {@link RequestQueue} before it starts their processing. This ensures that a single URL is not crawled multiple times.
47
+ * If both {@apilink CheerioCrawlerOptions.requestList} and {@apilink CheerioCrawlerOptions.requestQueue} are used,
48
+ * the instance first processes URLs from the {@apilink RequestList} and automatically enqueues all of them
49
+ * to {@apilink RequestQueue} before it starts their processing. This ensures that a single URL is not crawled multiple times.
245
50
  *
246
- * The crawler finishes when there are no more {@link Request} objects to crawl.
51
+ * The crawler finishes when there are no more {@apilink Request} objects to crawl.
247
52
  *
248
53
  * We can use the `preNavigationHooks` to adjust `gotOptions`:
249
54
  *
@@ -258,28 +63,20 @@ export interface CheerioCrawlerEnqueueLinksOptions extends Omit<EnqueueLinksOpti
258
63
  * By default, `CheerioCrawler` only processes web pages with the `text/html`
259
64
  * and `application/xhtml+xml` MIME content types (as reported by the `Content-Type` HTTP header),
260
65
  * and skips pages with other content types. If you want the crawler to process other content types,
261
- * use the {@link CheerioCrawlerOptions.additionalMimeTypes} constructor option.
66
+ * use the {@apilink CheerioCrawlerOptions.additionalMimeTypes} constructor option.
262
67
  * Beware that the parsing behavior differs for HTML, XML, JSON and other types of content.
263
- * For details, see {@link CheerioCrawlerOptions.requestHandler}.
68
+ * For more details, see {@apilink CheerioCrawlerOptions.requestHandler}.
264
69
  *
265
70
  * New requests are only dispatched when there is enough free CPU and memory available,
266
- * using the functionality provided by the {@link AutoscaledPool} class.
267
- * All {@link AutoscaledPool} configuration options can be passed to the `autoscaledPoolOptions`
71
+ * using the functionality provided by the {@apilink AutoscaledPool} class.
72
+ * All {@apilink AutoscaledPool} configuration options can be passed to the `autoscaledPoolOptions`
268
73
  * parameter of the `CheerioCrawler` constructor. For user convenience, the `minConcurrency` and `maxConcurrency`
269
- * {@link AutoscaledPool} options are available directly in the `CheerioCrawler` constructor.
74
+ * {@apilink AutoscaledPool} options are available directly in the `CheerioCrawler` constructor.
270
75
  *
271
76
  * **Example usage:**
272
77
  *
273
78
  * ```javascript
274
- * // Prepare a list of URLs to crawl
275
- * const requestList = await RequestList.open(null, [
276
- * { url: 'http://www.example.com/page-1' },
277
- * { url: 'http://www.example.com/page-2' },
278
- * ]);
279
- *
280
- * // Crawl the URLs
281
79
  * const crawler = new CheerioCrawler({
282
- * requestList,
283
80
  * async requestHandler({ request, response, body, contentType, $ }) {
284
81
  * const data = [];
285
82
  *
@@ -297,147 +94,39 @@ export interface CheerioCrawlerEnqueueLinksOptions extends Omit<EnqueueLinksOpti
297
94
  * },
298
95
  * });
299
96
  *
300
- * await crawler.run();
97
+ * await crawler.run([
98
+ * 'http://www.example.com/page-1',
99
+ * 'http://www.example.com/page-2',
100
+ * ]);
301
101
  * ```
302
102
  * @category Crawlers
303
103
  */
304
- export declare class CheerioCrawler extends BasicCrawler<CheerioCrawlingContext> {
305
- readonly config: Configuration;
306
- /**
307
- * A reference to the underlying {@link ProxyConfiguration} class that manages the crawler's proxies.
308
- * Only available if used by the crawler.
309
- */
310
- proxyConfiguration?: ProxyConfiguration;
311
- protected userRequestHandlerTimeoutMillis: number;
312
- protected preNavigationHooks: CheerioHook[];
313
- protected postNavigationHooks: CheerioHook[];
314
- protected persistCookiesPerSession: boolean;
315
- protected navigationTimeoutMillis: number;
316
- protected ignoreSslErrors: boolean;
317
- protected suggestResponseEncoding?: string;
318
- protected forceResponseEncoding?: string;
319
- protected readonly supportedMimeTypes: Set<string>;
320
- protected static optionsShape: {
321
- handlePageFunction: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
322
- navigationTimeoutSecs: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
323
- ignoreSslErrors: import("ow").BooleanPredicate & import("ow").BasePredicate<boolean | undefined>;
324
- additionalMimeTypes: import("ow").ArrayPredicate<string>;
325
- suggestResponseEncoding: import("ow").StringPredicate & import("ow").BasePredicate<string | undefined>;
326
- forceResponseEncoding: import("ow").StringPredicate & import("ow").BasePredicate<string | undefined>;
327
- proxyConfiguration: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
328
- persistCookiesPerSession: import("ow").BooleanPredicate & import("ow").BasePredicate<boolean | undefined>;
329
- preNavigationHooks: import("ow").ArrayPredicate<unknown> & import("ow").BasePredicate<unknown[] | undefined>;
330
- postNavigationHooks: import("ow").ArrayPredicate<unknown> & import("ow").BasePredicate<unknown[] | undefined>;
331
- requestList: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
332
- requestQueue: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
333
- requestHandler: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
334
- handleRequestFunction: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
335
- requestHandlerTimeoutSecs: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
336
- handleRequestTimeoutSecs: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
337
- errorHandler: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
338
- failedRequestHandler: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
339
- handleFailedRequestFunction: import("ow").Predicate<Function> & import("ow").BasePredicate<Function | undefined>;
340
- maxRequestRetries: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
341
- maxRequestsPerCrawl: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
342
- autoscaledPoolOptions: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
343
- sessionPoolOptions: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
344
- useSessionPool: import("ow").BooleanPredicate & import("ow").BasePredicate<boolean | undefined>;
345
- minConcurrency: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
346
- maxConcurrency: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
347
- maxRequestsPerMinute: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
348
- log: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
349
- };
104
+ export declare class CheerioCrawler extends HttpCrawler<CheerioCrawlingContext> {
350
105
  /**
351
106
  * All `CheerioCrawler` parameters are passed via an options object.
352
107
  */
353
108
  constructor(options?: CheerioCrawlerOptions, config?: Configuration);
354
- /**
355
- * **EXPERIMENTAL**
356
- * Function for attaching CrawlerExtensions such as the Unblockers.
357
- * @param extension Crawler extension that overrides the crawler configuration.
358
- */
359
- use(extension: CrawlerExtension): void;
360
- /**
361
- * Wrapper around requestHandler that opens and closes pages etc.
362
- */
363
- protected _runRequestHandler(crawlingContext: CheerioCrawlingContext): Promise<void>;
364
- protected _handleNavigation(crawlingContext: CheerioCrawlingContext): Promise<void>;
365
- /**
366
- * Sets the cookie header to `gotOptions` based on the provided request and session headers, as well as any changes that occurred due to hooks.
367
- */
368
- private _applyCookies;
369
- /**
370
- * Function to make the HTTP request. It performs optimizations
371
- * on the request such as only downloading the request body if the
372
- * received content type matches text/html, application/xml, application/xhtml+xml.
373
- */
374
- protected _requestFunction({ request, session, proxyUrl, gotOptions }: RequestFunctionOptions): Promise<IncomingMessage>;
375
- /**
376
- * Encodes and parses response according to the provided content type
377
- */
378
- protected _parseResponse(request: Request, responseStream: IncomingMessage): Promise<{
109
+ protected _parseHTML(response: IncomingMessage, isXml: boolean, crawlingContext: CheerioCrawlingContext): Promise<{
379
110
  dom: unknown;
380
- isXml: boolean;
381
- response: IncomingMessage;
382
- contentType: {
383
- type: string;
384
- encoding: BufferEncoding;
385
- };
386
- body?: undefined;
387
- } | {
388
- body: Buffer;
389
- response: IncomingMessage;
390
- contentType: {
391
- type: string;
392
- encoding: BufferEncoding;
393
- };
394
- dom?: undefined;
395
- isXml?: undefined;
111
+ $: cheerio.CheerioAPI;
112
+ readonly body: string;
113
+ enqueueLinks: (enqueueOptions?: CheerioCrawlerEnqueueLinksOptions) => Promise<BatchAddRequestsResult>;
396
114
  }>;
397
- /**
398
- * Combines the provided `requestOptions` with mandatory (non-overridable) values.
399
- */
400
- protected _getRequestOptions(request: Request, session?: Session, proxyUrl?: string, gotOptions?: OptionsInit): OptionsInit & {
401
- isStream: true;
402
- };
403
- protected _encodeResponse(request: Request, response: IncomingMessage, encoding: BufferEncoding): {
404
- encoding: BufferEncoding;
405
- response: IncomingMessage;
406
- };
407
115
  protected _parseHtmlToDom(response: IncomingMessage): Promise<unknown>;
408
- /**
409
- * Checks and extends supported mime types
410
- */
411
- protected _extendSupportedMimeTypes(additionalMimeTypes: (string | RequestLike | ResponseLike)[]): void;
412
- /**
413
- * Handles timeout request
414
- */
415
- protected _handleRequestTimeout(session?: Session): void;
416
- private _abortDownloadOfBody;
417
- /**
418
- * @internal wraps public utility for mocking purposes
419
- */
420
- private _requestAsBrowser;
421
116
  }
422
117
  interface EnqueueLinksInternalOptions {
423
118
  options?: CheerioCrawlerEnqueueLinksOptions;
424
- $: CheerioRoot | null;
119
+ $: cheerio.CheerioAPI | null;
425
120
  requestQueue: RequestQueue;
426
121
  originalRequestUrl: string;
427
122
  finalRequestUrl?: string;
428
123
  }
429
124
  /** @internal */
430
125
  export declare function cheerioCrawlerEnqueueLinks({ options, $, requestQueue, originalRequestUrl, finalRequestUrl }: EnqueueLinksInternalOptions): Promise<BatchAddRequestsResult>;
431
- interface RequestFunctionOptions {
432
- request: Request;
433
- session?: Session;
434
- proxyUrl?: string;
435
- gotOptions: OptionsInit;
436
- }
437
126
  /**
438
- * Creates new {@link Router} instance that works based on request labels.
439
- * This instance can then serve as a `requestHandler` of your {@link CheerioCrawler}.
440
- * Defaults to the {@link CheerioCrawlingContext}.
127
+ * Creates new {@apilink Router} instance that works based on request labels.
128
+ * This instance can then serve as a `requestHandler` of your {@apilink CheerioCrawler}.
129
+ * Defaults to the {@apilink CheerioCrawlingContext}.
441
130
  *
442
131
  * > Serves as a shortcut for using `Router.create<CheerioCrawlingContext>()`.
443
132
  *
@@ -458,6 +147,6 @@ interface RequestFunctionOptions {
458
147
  * await crawler.run();
459
148
  * ```
460
149
  */
461
- export declare function createCheerioRouter<Context extends CheerioCrawlingContext = CheerioCrawlingContext>(): import("@crawlee/basic").RouterHandler<Context>;
150
+ export declare function createCheerioRouter<Context extends CheerioCrawlingContext = CheerioCrawlingContext>(): import("@crawlee/http").RouterHandler<Context>;
462
151
  export {};
463
152
  //# sourceMappingURL=cheerio-crawler.d.ts.map
@@ -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