@crawlee/cheerio 4.0.0-beta.230 → 4.0.0-beta.232
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.
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { CrawlingContext, DOMCrawlingContext, ErrorHandler, GetUserDataFromRequest, HttpCrawlerOptions, RequestHandler, RouterHandler, RouterRoutes, RouteSchemas, RoutesFromSchemas } from '@crawlee/http';
|
|
2
2
|
import { DOMCrawler } from '@crawlee/http';
|
|
3
3
|
import type { Dictionary } from '@crawlee/types';
|
|
4
|
+
import type { Cheerio } from 'cheerio';
|
|
5
|
+
import type { AnyNode } from 'domhandler';
|
|
4
6
|
import type { CheerioParseResult } from './cheerio-parser.js';
|
|
5
7
|
export type CheerioErrorHandler<UserData extends Dictionary = any, // with default to Dictionary we cant use a typed router in untyped crawler
|
|
6
8
|
JSONData extends Dictionary = any, // with default to Dictionary we cant use a typed router in untyped crawler
|
|
@@ -10,7 +12,7 @@ JSONData extends Dictionary = any, // with default to Dictionary we cant use a t
|
|
|
10
12
|
Routes extends Record<keyof Routes, Dictionary> = Record<string, UserData>, StatisticStateExtension extends object = {}> extends Omit<HttpCrawlerOptions<CheerioCrawlingContext<UserData, JSONData>, ContextExtension, ExtendedContext, Routes, StatisticStateExtension>, 'contextPipelineBuilder'> {
|
|
11
13
|
}
|
|
12
14
|
export interface CheerioCrawlingContext<UserData extends Dictionary = any, // with default to Dictionary we cant use a typed router in untyped crawler
|
|
13
|
-
JSONData extends Dictionary = any> extends DOMCrawlingContext<CheerioParseResult, UserData, JSONData> {
|
|
15
|
+
JSONData extends Dictionary = any> extends DOMCrawlingContext<CheerioParseResult, Cheerio<AnyNode>, Cheerio<AnyNode>, UserData, JSONData> {
|
|
14
16
|
}
|
|
15
17
|
export type CheerioRequestHandler<UserData extends Dictionary = any, // with default to Dictionary we cant use a typed router in untyped crawler
|
|
16
18
|
JSONData extends Dictionary = any> = RequestHandler<CheerioCrawlingContext<UserData, JSONData>>;
|
|
@@ -93,7 +95,7 @@ JSONData extends Dictionary = any> = RequestHandler<CheerioCrawlingContext<UserD
|
|
|
93
95
|
* ```
|
|
94
96
|
* @category Crawlers
|
|
95
97
|
*/
|
|
96
|
-
export declare class CheerioCrawler<ContextExtension = Dictionary<never>, ExtendedContext extends CheerioCrawlingContext = CheerioCrawlingContext & ContextExtension, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest<CheerioCrawlingContext['request']>>, StatisticStateExtension extends object = {}> extends DOMCrawler<CheerioParseResult, ContextExtension, ExtendedContext, Routes, StatisticStateExtension> {
|
|
98
|
+
export declare class CheerioCrawler<ContextExtension = Dictionary<never>, ExtendedContext extends CheerioCrawlingContext = CheerioCrawlingContext & ContextExtension, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest<CheerioCrawlingContext['request']>>, StatisticStateExtension extends object = {}> extends DOMCrawler<CheerioParseResult, Cheerio<AnyNode>, Cheerio<AnyNode>, ContextExtension, ExtendedContext, Routes, StatisticStateExtension> {
|
|
97
99
|
/**
|
|
98
100
|
* All `CheerioCrawler` parameters are passed via an options object.
|
|
99
101
|
*/
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { DOMParser } from '@crawlee/http';
|
|
2
|
-
import type { CheerioAPI } from 'cheerio';
|
|
2
|
+
import type { Cheerio, CheerioAPI } from 'cheerio';
|
|
3
|
+
import type { AnyNode } from 'domhandler';
|
|
3
4
|
export interface CheerioParseResult {
|
|
4
5
|
$: CheerioAPI;
|
|
5
6
|
body: string;
|
|
@@ -8,4 +9,4 @@ export interface CheerioParseResult {
|
|
|
8
9
|
* A {@link DOMParser} backed by [cheerio](https://www.npmjs.com/package/cheerio). Pass it to a
|
|
9
10
|
* {@link DOMCrawler} to get the crawling context {@link CheerioCrawler} provides.
|
|
10
11
|
*/
|
|
11
|
-
export declare function cheerioParser(): DOMParser<CheerioParseResult
|
|
12
|
+
export declare function cheerioParser(): DOMParser<CheerioParseResult, Cheerio<AnyNode>, Cheerio<AnyNode>>;
|
|
@@ -21,7 +21,11 @@ export function cheerioParser() {
|
|
|
21
21
|
return { $, body };
|
|
22
22
|
},
|
|
23
23
|
extractLinks: ({ $ }, selector, baseUrl) => extractUrlsFromCheerio($, selector, baseUrl),
|
|
24
|
-
|
|
24
|
+
querySelectorAll: ({ $ }, selector) => $(selector),
|
|
25
|
+
querySelectorOne: ({ $ }, selector) => {
|
|
26
|
+
const match = $(selector).first();
|
|
27
|
+
return match.length ? match : undefined;
|
|
28
|
+
},
|
|
25
29
|
toCheerio: ({ $ }) => $,
|
|
26
30
|
};
|
|
27
31
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crawlee/cheerio",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.232",
|
|
4
4
|
"description": "The scalable web crawling and scraping library for JavaScript/Node.js. Enables development of data extraction and web automation jobs (not only) with headless Chrome and Puppeteer.",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=22.13.0"
|
|
@@ -47,10 +47,11 @@
|
|
|
47
47
|
"access": "public"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@crawlee/http": "4.0.0-beta.
|
|
51
|
-
"@crawlee/types": "4.0.0-beta.
|
|
52
|
-
"@crawlee/utils": "4.0.0-beta.
|
|
50
|
+
"@crawlee/http": "4.0.0-beta.232",
|
|
51
|
+
"@crawlee/types": "4.0.0-beta.232",
|
|
52
|
+
"@crawlee/utils": "4.0.0-beta.232",
|
|
53
53
|
"cheerio": "^1.0.0",
|
|
54
|
+
"domhandler": "^6.0.0",
|
|
54
55
|
"htmlparser2": "^10.0.0",
|
|
55
56
|
"tslib": "^2.8.1"
|
|
56
57
|
},
|
|
@@ -61,5 +62,5 @@
|
|
|
61
62
|
}
|
|
62
63
|
}
|
|
63
64
|
},
|
|
64
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "5eab8f877242d46d7cae13b640d8e1adbf194911"
|
|
65
66
|
}
|