Reputation: 501
We have a requirement to load the input HTML string into browser kind of environment, run the html (which should internally run all the inline scripts i.e there are a few ajax calls) and then provide the rendered HTML as output.
Is this possible with node?
Is there any node module which we can use for this purpose.
Please help in this regard.
Upvotes: 0
Views: 1225
Reputation: 2164
Sound like you looking for headless browser for NodeJS. see a list here http://github.com/dhamaniasad/HeadlessBrowsers
This is example from CasperJS
You can install as Node module
npm install -g casperjs
And
var casper = require('casper').create();
casper.start('http://www.google.fr/', function() {
this.echo(this.getHTML());
});
casper.run();
Run
casperjs app.js
For NODEJS runtime
Try Nightmare
Install
npm install nightmare
code
var Nightmare = require('nightmare');
var nightmare = Nightmare({ show: false });
nightmare.goto("http://www.google.com")
.evaluate(function(){
return document.body.outerHTML;
})
.end()
.then(function (result) {
console.log(result)
})
Run
nodejs app.js
Upvotes: 1