Interface: CheerioAPI()
A querying function, bound to a document created from the provided markup.
Also provides several helper methods for dealing with the document as a whole.
Extends
StaticType
CheerioAPI<
T
,S
>(selector
?,context
?,root
?,options
?):Cheerio
<S
extendsSelectorType
?Element
:T
>
A querying function, bound to a document created from the provided markup.
Also provides several helper methods for dealing with the document as a whole.
Type Parameters
• T extends AnyNode
• S extends string
Parameters
• selector?: S
| BasicAcceptedElems
<T
>
Either a selector to look for within the document, or the contents of a new Cheerio instance.
• context?: null
| BasicAcceptedElems
<AnyNode
>
Either a selector to look for within the root, or the contents of the document to query.
• root?: BasicAcceptedElems
<Document
>
Optional HTML document string.
• options?: CheerioOptions
Returns
Cheerio
<S
extends SelectorType
? Element
: T
>
Example
$('ul .pear').attr('class');
//=> pear
$('li[class=orange]').html();
//=> Orange
$('.apple', '#fruits').text();
//=> Apple
Optionally, you can also load HTML by passing the string as the selector:
$('<ul id="fruits">...</ul>');
Or the context:
$('ul', '<ul id="fruits">...</ul>');
Or as the root:
$('li', 'ul', '<ul id="fruits">...</ul>');
Defined in
Deprecated
load()
load: (
content
,options
?,isDocument
) =>CheerioAPI
The .load
static method defined on the "loaded" Cheerio factory function
is deprecated. Users are encouraged to instead use the load
function
exported by the Cheerio module.
Parameters
• content: string
| AnyNode
| AnyNode
[] | Buffer
• options?: null
| CheerioOptions
• isDocument?: boolean
= true
Returns
Deprecated
Use the load
function exported by the Cheerio module.
Example
const $ = cheerio.load('<h1>Hello, <span>world</span>.</h1>');
Defined in
Other
contains
Re-exports contains
merge
Re-exports merge
fn
fn:
Cheerio
<any
>
Mimic jQuery's prototype alias for plugin authors.
Defined in
Static
extract()
extract<
M
>(this
,map
):ExtractedMap
<M
>
Extract multiple values from a document, and store them in an object.
Type Parameters
• M extends ExtractMap
Parameters
• this: CheerioAPI
• map: M
An object containing key-value pairs. The keys are the names of the properties to be created on the object, and the values are the selectors to be used to extract the values.
Returns
ExtractedMap
<M
>
An object containing the extracted values.
Inherited from
StaticType.extract