PhantomJS中的评估似乎不起作用 [英] Evaluate in PhantomJS doesn't seem to work
本文介绍了PhantomJS中的评估似乎不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到了JavaScript魔术问题。当我执行此代码时:
I have a problem with JavaScript magic. When I execute this code:
var page = require('webpage').create();
var url="http://google.com";
page.open(url, function (status){
if (status!== "success") {
console.log("Fail to load: "+url)
}else{
console.log('1');
page.evaluate(function() {
console.log('2');
});
console.log('3');
}
phantom.exit();
});
控制台只有1和3而且没有2.有人可以说为什么?
console have only 1 and 3 and no 2. Can anyone say why?
如果我在代码后粘贴 DOM操作示例(但它永远不会执行)我有我的两个。我忘记了重要的事情吗?
If I paste after my code DOM manipulation example (but it never execute) I have my two. Did I forget something important?
推荐答案
默认情况下,PhantomJS不会在.evaluate()语句中记录控制台消息。只需包含
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
这篇关于PhantomJS中的评估似乎不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文