使用nodejs捕获控制台输出

时间:2017-05-03 07:41:34

标签: javascript node.js phantomjs

我有这个远程网页:

的test.html

<html>
    <body>
        <script>
            console.log(5 + 6);
        </script>
    </body>
</html>

我想在node.js中创建一个可以返回&#34; 11&#34;

的脚本

我尝试使用phantom.js。但是,我没有得到任何结果。

var phantom = require('phantom');
phantom.create()
.then(function(ph) {
    ph.createPage()
    .then(function(page) {
        page.open('http://localhost:8888/test.html')
        .then(function(status) {
            console.log(status);
            page.property('onConsoleMessage')
            .then(function(content) {
                console.log(content);
                page.close();
                ph.exit();
            });
        });
    });
});

0 个答案:

没有答案
相关问题