Skip to main content

Interface: CheerioRequestOptions

Options accepted by Cheerio.

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

Extends

Properties

baseURI?

optional baseURI: string | URL

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

Inherited from

DecodeStreamOptions.baseURI

Defined in

src/options.ts:45


encoding?

optional encoding: SnifferOptions

Inherited from

DecodeStreamOptions.encoding

Defined in

src/batteries.ts:137


onParseError?

optional onParseError: null | ParserErrorHandler

Callback for parse errors.

Default

null

Inherited from

DecodeStreamOptions.onParseError

Defined in

node_modules/parse5/dist/cjs/parser/index.d.ts:63


pseudos?

optional pseudos: Record<string, string | (elem, value?) => 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

Inherited from

DecodeStreamOptions.pseudos

Defined in

src/options.ts:84


quirksMode?

optional quirksMode: boolean

Is the document in quirks mode?

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

Default

false

Inherited from

DecodeStreamOptions.quirksMode

Defined in

src/options.ts:54


requestOptions?

optional requestOptions: object & Omit<RequestOptions, "origin" | "path">

The options passed to undici's stream method.

Type declaration

dispatcher?

optional dispatcher: Dispatcher

Defined in

src/batteries.ts:173


scriptingEnabled?

optional scriptingEnabled: boolean

The scripting flag. If set to true, noscript element content will be parsed as text.

Default

true

Inherited from

DecodeStreamOptions.scriptingEnabled

Defined in

node_modules/parse5/dist/cjs/parser/index.d.ts:40


sourceCodeLocationInfo?

optional sourceCodeLocationInfo: boolean

Enables 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.

Default

false

Inherited from

DecodeStreamOptions.sourceCodeLocationInfo

Defined in

node_modules/parse5/dist/cjs/parser/index.d.ts:51


treeAdapter?

optional treeAdapter: TreeAdapter<Htmlparser2TreeAdapterMap>

Specifies the resulting tree format.

Default

treeAdapters.default

Inherited from

DecodeStreamOptions.treeAdapter

Defined in

node_modules/parse5/dist/cjs/parser/index.d.ts:57


xml?

optional xml: boolean | HTMLParser2Options

Recommended way of configuring htmlparser2 when wanting to parse XML.

This will switch Cheerio to use htmlparser2.

Default

false

Inherited from

DecodeStreamOptions.xml

Defined in

src/options.ts:34


xmlMode?

optional xmlMode: boolean

Enable xml mode, which will switch Cheerio to use htmlparser2.

Deprecated

Please use the xml option instead.

Default

false

Inherited from

DecodeStreamOptions.xmlMode

Defined in

src/options.ts:42