JavaScript to Html
JavaScript to Html
给定一个包含JavaScript代码的网页,我想自动生成一个结果html(通过CLI工具或使用某种语言的库)
例如,给定test.html
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = "Hello JavaScript!";
</script>
</body>
</html>
我想得到
<html>
<body>
<p id="demo">Hello JavaScript!</p>
<script>
document.getElementById("demo").innerHTML = "Hello JavaScript!";
</script>
</body>
</html>
快速搜索后,watin似乎会做你想做的事。
它的目标是自动化测试,但当它到达一个页面时,它会执行所有的js以及ajax调用等。看起来你也可以从中获取结果html。
答案基于@torazaburo 的评论
事实上,phantomjs能够评估javascript并生成html。
以下是执行phantomjs load_page.js path_to/test.html
的情况
var page = require('webpage').create(),
system = require('system'),
page_address;
var fs = require('fs');
if (system.args.length === 1){
console.log('Usage: phantomjs ' + system.args[0] + ' <page_to_load:http://www.google.com>');
phantom.exit();
}
page_address = system.args[1]
page.open(page_address, function(status){
console.log('Status:' + status);
if (status === 'success' ){
fs.write('phantom_result.html', page.content, 'w')
}
phantom.exit();
});
相关文章:
- how to convert html <div> to pdf
- SCEditor BBcode to HTML parsing
- html image blob to base64
- Javascript: regexp to remove .html
- Javascript, XML to HTML
- CSV to HTML tables
- How to do "HTML FORM action=location.replace('nextp
- HTML to JS Object
- CSV to html table
- XML to HTML with jQuery
- "Share-to-Facebook" html / php / js
- Mootools Element to HTML
- Html-Javascript create select fied to and fro box
- jQuery for HTML to PHP - Function Error
- HTML to exe>阻止 Internet Explorer 对象中的 JavaScript 和 ActiveX 安
- dynamic PDF v/s HTML to PDF
- Javascript: Upload HTML to S3
- jQuery HTML to JSON
- jQuery add html to original-title?
- Html to pdf Jspdf