跳至主要内容

接口: CheerioRequestOptions

Cheerio 接受的选项。

请注意,仅当使用相关解析器时,解析器特定的选项才会被识别

扩展

属性

baseURI?

可选 baseURI: string | URL

文档的基准 URI。用于解析 hrefsrc 属性。

继承自

DecodeStreamOptions.baseURI

定义于

src/options.ts:42


encoding?

可选 encoding: SnifferOptions

继承自

DecodeStreamOptions.encoding

定义于

src/index.ts:146


onParseError?

可选 onParseError: null | ParserErrorHandler

解析错误的回调。

默认值

null

继承自

DecodeStreamOptions.onParseError

定义于

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


pseudos?

可选 pseudos: Record<string, string | (elem, value?) => boolean>

伪类扩展点。

从名称映射到字符串或函数。

  • 字符串值是一个选择器,元素必须匹配该选择器才能被选中。
  • 函数以元素作为第一个参数调用,可选参数作为第二个参数。如果它返回 true,则选择该元素。

示例

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

继承自

DecodeStreamOptions.pseudos

定义于

src/options.ts:81


quirksMode?

可选 quirksMode: boolean

文档是否处于怪异模式?

这将导致 .className#id 不区分大小写。

默认值

false

继承自

DecodeStreamOptions.quirksMode

定义于

src/options.ts:51


requestOptions?

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

传递给 undicistream 方法的选项。

类型声明

dispatcher?

可选 dispatcher: Dispatcher

定义于

src/index.ts:182


scriptingEnabled?

可选 scriptingEnabled: boolean

the 脚本标志。如果设置为 truenoscript 元素内容将被解析为文本。

默认值

true

继承自

DecodeStreamOptions.scriptingEnabled

定义于

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


sourceCodeLocationInfo?

可选 sourceCodeLocationInfo: boolean

启用源代码位置信息。启用后,每个节点(根节点除外)将具有 sourceCodeLocation 属性。如果节点不是空元素,sourceCodeLocation 将是 ElementLocation 对象,否则将是 Location。如果元素是由解析器隐式创建的(作为 树校正 的一部分),它的 sourceCodeLocation 属性将是 undefined

默认值

false

继承自

DecodeStreamOptions.sourceCodeLocationInfo

定义于

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


treeAdapter?

可选 treeAdapter: TreeAdapter<Htmlparser2TreeAdapterMap>

指定生成的树格式。

默认值

treeAdapters.default

继承自

DecodeStreamOptions.treeAdapter

定义于

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


xml?

可选 xml: boolean | HTMLParser2Options

在想要解析 XML 时配置 htmlparser2 的推荐方法。

这将切换 Cheerio 以使用 htmlparser2。

默认值

false

继承自

DecodeStreamOptions.xml

定义于

src/options.ts:31


xmlMode?

可选 xmlMode: boolean

启用 xml 模式,这将切换 Cheerio 以使用 htmlparser2。

已弃用

请使用 xml 选项代替。

默认值

false

继承自

DecodeStreamOptions.xmlMode

定义于

src/options.ts:39