Interface CheerioOptions

Options accepted by Cheerio.

Please note that parser-specific options are only recognized if the relevant parser is used.

Hierarchy

Properties

Tokenizer?: typeof default

Allows the default tokenizer to be overwritten.

baseURI?: string | URL

The base URI for the document. Used for the href and src props.

decodeEntities?: boolean

Decode entities within the document.

Default

true

lowerCaseAttributeNames?: boolean

If set to true, all attribute names will be lowercased. This has noticeable impact on speed.

Default

!xmlMode

lowerCaseTags?: boolean

If set to true, all tags will be lowercased.

Default

!xmlMode

pseudos?: Record<string, string | ((elem: Element, value?: null | string) => boolean)>

Extension point for pseudo-classes.

Maps from names to either strings of functions.

  • A string value is a selector that the element must match to be selected.
  • A function is called with the element as its first argument, and optional parameters second. If it returns true, the element is selected.

Example

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
quirksMode?: boolean

Is the document in quirks mode?

This will lead to .className and #id being case-insensitive.

Default

false

recognizeCDATA?: boolean

If set to true, CDATA sections will be recognized as text even if the xmlMode option is not enabled. NOTE: If xmlMode is set to true then CDATA sections will always be recognized as text.

Default

xmlMode

recognizeSelfClosing?: boolean

If set to true, self-closing tags will trigger the onclosetag event even if xmlMode is not set to true. NOTE: If xmlMode is set to true then self-closing tags will always be recognized.

Default

xmlMode

scriptingEnabled?: boolean

Disable scripting in parse5, so noscript tags would be parsed.

sourceCodeLocationInfo?: boolean

Enable location support for parse5.

withEndIndices?: boolean

Add an endIndex property to nodes. When the parser is used in a non-streaming fashion, endIndex is an integer indicating the position of the end of the node in the document.

Default

false

withStartIndices?: boolean

Add a startIndex property to nodes. When the parser is used in a non-streaming fashion, startIndex is an integer indicating the position of the start of the node in the document.

Default

false

xml?: boolean | HTMLParser2Options

Recommended way of configuring htmlparser2 when wanting to parse XML.

xmlMode?: boolean

Treat the markup as XML.

Default

false