接口: DecodeStreamOptions
Cheerio 接受的选项。
请注意,特定于解析器的选项仅在使用相关解析器时才被识别。
继承自
扩展自
属性
baseURI?
可选
baseURI:字符串
|URL
文档的基准 URI。用于解析 href
和 src
属性。
继承自
定义于
encoding?
可选
encoding:SnifferOptions
定义于
onParseError?
可选
onParseError:null
|ParserErrorHandler
解析错误的回调函数。
默认值
null
继承自
定义于
node_modules/parse5/dist/parser/index.d.ts:63
pseudos?
可选
pseudos:Record
<字符串
,字符串
| (elem
,value
?) =>布尔值
>
伪类的扩展点。
将名称映射到字符串或函数。
- 字符串值为元素必须匹配的 CSS 选择器,才能被选中。
- 函数接收元素作为第一个参数,可选参数作为第二个参数。如果函数返回 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
继承自
定义于
quirksMode?
可选
quirksMode:布尔值
文档是否处于怪异模式?
这将导致 .className
和 #id
不区分大小写。
默认值
false
继承自
定义于
scriptingEnabled?
可选
scriptingEnabled:布尔值
脚本标志。如果设置为 true
,则 noscript
元素的内容将被解析为文本。
默认值
true
继承自
CheerioOptions
.scriptingEnabled
定义于
node_modules/parse5/dist/parser/index.d.ts:40
sourceCodeLocationInfo?
可选
sourceCodeLocationInfo:布尔值
启用源代码位置信息。启用后,每个节点(根节点除外)都将具有 sourceCodeLocation
属性。如果节点不是空元素,sourceCodeLocation
将为 ElementLocation 对象,否则为 Location。如果元素是由解析器隐式创建的(作为树修正的一部分),则其 sourceCodeLocation
属性将为 undefined
。
默认值
false
继承自
CheerioOptions
.sourceCodeLocationInfo
定义于
node_modules/parse5/dist/parser/index.d.ts:51
treeAdapter?
可选
treeAdapter:TreeAdapter
<Htmlparser2TreeAdapterMap
>
指定最终的树格式。
默认值
treeAdapters.default
继承自
定义于
node_modules/parse5/dist/parser/index.d.ts:57
xml?
可选
xml:布尔值
|HTMLParser2Options
推荐在解析 XML 时配置 htmlparser2 的方式。
这将切换 Cheerio 以使用 htmlparser2。
默认值
false
继承自
定义于
xmlMode?
可选
xmlMode:布尔值
启用 XML 模式,这将切换 Cheerio 以使用 htmlparser2。
已弃用
请改用 xml
选项。
默认值
false