How to get html generated from javascript using phantomJS?

风格不统一 提交于 2020-01-24 01:24:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!