admin管理员组文章数量:1305299
I'm new to phantomJS and this is what I tried so far:
var page = require('webpage').create();
console.log('The default user agent is ' + page.settings.userAgent);
page.settings.userAgent = 'SpecialAgent';
page.open('', function (status) {
if (status !== 'success') {
console.log( 'Unable to access network' );
} else {
console.log( 'Opened ok' );
page.includeJs( '.8.2/jquery.min.js', function() {
console.log( 'include JS callback' );
page.evaluate(function(){
console.log('include JS callback - eval');
});
});
console.log( 'After include JS' );
}
phantom.exit();
});
but the output is
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
As you can see 'include JS callback'
and 'include JS callback - eval'
are not logged, where is the problem?
I'm new to phantomJS and this is what I tried so far:
var page = require('webpage').create();
console.log('The default user agent is ' + page.settings.userAgent);
page.settings.userAgent = 'SpecialAgent';
page.open('http://google.', function (status) {
if (status !== 'success') {
console.log( 'Unable to access network' );
} else {
console.log( 'Opened ok' );
page.includeJs( 'http://ajax.googleapis./ajax/libs/jquery/1.8.2/jquery.min.js', function() {
console.log( 'include JS callback' );
page.evaluate(function(){
console.log('include JS callback - eval');
});
});
console.log( 'After include JS' );
}
phantom.exit();
});
but the output is
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
As you can see 'include JS callback'
and 'include JS callback - eval'
are not logged, where is the problem?
1 Answer
Reset to default 12Fastest gun in the west Phantom-style problem. You're exiting too early. page.includeJs
is an asynchronous function, because it has to send a request to fetch the resource. You can see that, because it has a callback. You should move the phantom.exit();
to the end of the page.includeJs
callback. All further processing should also be triggered from/moved to the page.includeJs
callback.
If you want 'include JS callback - eval'
to appear you have to additionally register to the page.onConsoleMessage
event.
本文标签: javascriptPhantomJS39 includeJs is not executedStack Overflow
版权声明:本文标题:javascript - PhantomJS' includeJs is not executed - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741701149a2393296.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论