问题
var page = require('webpage').create();
page.open(url, function (status) {
if (status === 'fail') {
console.log("fail");
} else {
console.log(page.evaluate(function () {
var t0 = document.body.innerHTML;
return t0;
}));
}
phantom.exit();
});
When I do this way, I can't get the html generated from js.
回答1:
This is not the correct way to return anything from the page scope to the phantom's scope.
You should consider using
window.callPhantom method and page.onCallback event.
来源:https://stackoverflow.com/questions/18526140/how-to-get-html-generated-from-javascript-using-phantomjs