Evaluate in PhantomJS doesn't seem to work

十年热恋 提交于 2019-12-01 21:35:24

PhantomJS won't log console messages in .evaluate() statements by default. Just include

page.onConsoleMessage = function (msg) {
    console.log(msg);
};

See this page for more details/in-depth example:

http://code.google.com/p/phantomjs/wiki/QuickStart#Code_Evaluation

From Google Code

Any console message from a web page, including from the code inside evaluate(), will not be displayed by default. To override this behavior, use the onConsoleMessage callback.

If you only want select logs to come through, you can return the value that you'd like to print.

For example:

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