Get Generated Html After Js Manipulates The Dom And Pass Request Headers
I need to get the generated HTML source of the page after JS DOM manipulation has all been done. I was using Phantomas https://github.com/macbre/phantomas for this purpose, but unf
Solution 1:
You can use "PhantomJS WebKit scriptable".
Specify customHeaders
and get the page.content
:
var webPage = require('webpage');
var page = webPage.create();
page.customHeaders = {
"X-Test": "foo",
"DNT": "1"
};
page.open('http://phantomjs.org', function (status) {
var content = page.content;
console.log('Content: ' + content);
phantom.exit();
});
Save it to test.js
and run:
phantomjs test.js
Solution 2:
You can use casperjs
.
Pass headers
in a settings
object to the open()
function and use getPageContent()
to get the HTML source of the page:
var casper = require('casper').create();
var headers = {
'Accept-Language': 'en-US,en;q=0.8',
'HEADER-XYZ': 'HEADER-XYZ-DATA'
};
casper.start().then(function () {
this.open("http://casperjs.org", {
method: 'get',
headers: headers
});
});
casper.then(function() {
console.log(this.getPageContent());
});
casper.run(function() {
this.exit();
});
Post a Comment for "Get Generated Html After Js Manipulates The Dom And Pass Request Headers"