Javascript 幻影';includeJs未执行

Javascript 幻影';includeJs未执行,javascript,phantomjs,Javascript,Phantomjs,我对phantomJS是新手,这是我迄今为止尝试过的: var page=require('webpage').create(); console.log('默认的用户代理是'+page.settings.userAgent); page.settings.userAgent='SpecialAgent'; 第页打开('http://google.com,功能(状态){ 如果(状态!=“成功”){ log('无法访问网络'); }否则{ log('Opened ok'); 第页,包括http:/

我对phantomJS是新手,这是我迄今为止尝试过的:

var page=require('webpage').create();
console.log('默认的用户代理是'+page.settings.userAgent);
page.settings.userAgent='SpecialAgent';
第页打开('http://google.com,功能(状态){
如果(状态!=“成功”){
log('无法访问网络');
}否则{
log('Opened ok');
第页,包括http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js,函数(){
log('include JS callback');
page.evaluate(函数(){
log('include JS callback-eval');
});
});
log('After include JS');
}
phantom.exit();
});
但结果是

The default user agent is Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.9.8 Safari/534.34
Opened ok
After include JS

正如您所看到的,
'include JS callback'
'include JS callback-eval'
未被记录,问题出在哪里?

西方幻影式问题中最快的枪。你离开得太早了
page.includeJs
是一个异步函数,因为它必须发送请求才能获取资源。你可以看到,因为它有一个回调。您应该移动
phantom.exit()
页面的末尾。includeJs
回调。所有进一步的处理也应该从
页面触发/移动到
页面。includeJs
回调


如果您希望
“include JS callback-eval”
出现,您必须另外注册该事件。

只是指向此注册的链接-不,这是为其他人准备的(如果将来有人发现此链接),如何使用此
页面。OnConsolleMessage
,我相信您知道;-)