如何使用querySelector
选择整个文档以下是代码:
var jsdom = require('jsdom');
const {JSDOM} = jsdom;
const dom = new JSDOM(htmlSource)
var q = dom.window.document.querySelector.bind(dom.window.document);
q("title").innerHTML = "This is the title replaced"
console.log(q("html").outerHTML);
htmlSource = q("html").outerHTML;
fs.writeFileSync("public/html/index2.html", htmlSource, "utf8");
我想将已更改的title
元素重写为新文件index2.html
。我能够输出更改的元素但无法写入新版本的文件。我怎么能这样做?
答案 0 :(得分:1)
您可以像dom.window.document.title = "new title"
https://developer.mozilla.org/en-US/docs/Web/API/Document/title