electron 可以解析渲染 vue 等前端框架生成html
Uncategorized
|
|
14 views
|
2024-05-07 15:29:10
electron
mainWindow.webContents.on('dom-ready', () => {
// console.log(document.documentElement.outerHTML);
// 执行JavaScript来获取HTML内容
mainWindow.webContents.executeJavaScript(`
// 获取HTML内容
document.documentElement.outerHTML;
`)
.then(htmlContent => { // 打印HTML内容
console.log(htmlContent);
// 将HTML内容写入文件
fs.writeFile('page.html', htmlContent, 'utf8', (err) => { if (err) { console.error('Error writing file:', err); return;
}
console.log('HTML content saved to page.html'); });
})
.catch(error => { console.error('Error executing JavaScript:', error); });
});
No comments yet. Be the first to comment!