Wednesday, 3 May 2017

Capture console output with nodejs

Hello i have this remote web page :

test.html

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

I want create one script in nodejs that can get the result "11"

i try to use phantomjs but i dont have any result.

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();
      });
    });
  });
});



via ggmac23

No comments:

Post a Comment