我在PhantomJS中运行jQuery时遇到问题.我找到了这个答案,其中讨论了在evaluate函数中没有可用的变量,但问题是关于节点模块,在我的例子中我只调用console.logevaluate函数.我也把这个问题放在了GitHub上.
以前,对于某些页面,以下evaluate代码未执行.现在@ b1f56gd4已经提供了一些帮助,它现在打印消息; 我无法执行它,但现在我可以看到:
https://login.yahoo.com/上的页面从http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js运行了不安全的内容.
我无法从不同的域加载jQuery,--local-to-remote-url-access=true或者--web-security=false选项没有区别.
我将尝试在本地加载jQuery.这是代码:
console.log('Loading a web page');
var url = 'https://login.yahoo.com/';
var page = require('webpage').create();
console.log('Setting error handling');
page.onConsoleMessage = function (msg) {
console.log(msg);
};
page.onError = function (msg, trace) {
console.log(msg);
trace.forEach(function(item) {
console.log(' ', item.file, ':', item.line);
})
phantom.exit();
}
console.log('Error handling is set');
console.log('Opening page');
page.open(url, function (status) {
if (status != 'success') {
console.log('F-' + status);
} …Run Code Online (Sandbox Code Playgroud)