OptionalbaseThe base URI for the document. Used to resolve the href and src props.
OptionalencodingOptionalonCallback for parse errors.
OptionalpseudosExtension point for pseudo-classes.
Maps from names to either strings of functions.
const $ = cheerio.load(
'<div class="foo"></div><div data-bar="boo"></div>',
{
pseudos: {
// `:foo` is an alias for `div.foo`
foo: 'div.foo',
// `:bar(val)` is equivalent to `[data-bar=val s]`
bar: (el, val) => el.attribs['data-bar'] === val,
},
},
);
$(':foo').length; // 1
$('div:bar(boo)').length; // 1
$('div:bar(baz)').length; // 0
OptionalquirksIs the document in quirks mode?
This will lead to .className and #id being case-insensitive.
OptionalrequestThe options passed to undici's stream method.
OptionalscriptingThe scripting flag. If set
to true, noscript element content will be parsed as text.
OptionalsourceEnables source code location information. When enabled, each node (except the root node)
will have a sourceCodeLocation property. If the node is not an empty element, sourceCodeLocation will
be a ElementLocation object, otherwise it will be Location.
If the element was implicitly created by the parser (as part of
tree correction),
its sourceCodeLocation property will be undefined.
OptionaltreeSpecifies the resulting tree format.
OptionalxmlRecommended way of configuring htmlparser2 when wanting to parse XML.
This will switch Cheerio to use htmlparser2.
OptionalxmlEnable xml mode, which will switch Cheerio to use htmlparser2.
Options accepted by Cheerio.
Please note that parser-specific options are only recognized if the relevant parser is used.