【发布时间】:2019-07-18 16:41:40
【问题描述】:
我有一个简单但格式不是很好的 html 页面,其中包含所有错误:
<HTML>
<head>
<title>Official game sheet</title>
</head>
<body class="sheet">
</BODY>
</HTML>
尝试在从此 html 解析的文档上应用 xpath //title。
const document = parse5.parse(xmlString);
const xhtml = xmlser.serializeToString(document);
const doc = new dom().parseFromString(xhtml);
const select = xpath.useNamespaces({
"x": "http://www.w3.org/1999/xhtml"
});
const nodes = select("//title", doc);
console.log(nodes);
尝试了from here 的解决方案,但没有成功。返回的节点列表为空。
【问题讨论】: