【实例简介】
【实例截图】
【核心代码】
let {JSDOM} = require(“jsdom”);
//渲染js执行后的结果
const dom = new JSDOM(`
`, { runScripts: “dangerously” });
console.log(dom.window.document.body.outerHTML);
//读取网页html内容
console.log(“starts”)
JSDOM.fromURL(“http://www.haolizi.net”).then((dom) => {
console.log(dom.serialize());
});
//读取网页html并执行脚本
JSDOM.fromURL(“http://www.haolizi.net”, {runScripts: ‘dangerously’}).then((dom) => {
console.log(dom.serialize());
});