How to get html generated from javascript using ph

2019-06-11 13:27发布

问题:

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.