【发布时间】:2015-09-14 22:41:21
【问题描述】:
我在 Mac OS X Yosemite 上使用 PhantomJS 2.0.0:
$ phantomjs --version
2.0.0
如下所示,我的脚本似乎挂在调用$('h1').size() 的行:
system = require('system');
function usage() {
console.log("usage: phantomjs " + system.args[0] + " <url>");
phantom.exit(1);
}
console.log("system.args.length=" + system.args.length);
if (system.args.length != 2) {
console.log("usage bad....");
usage();
} else {
var url = system.args[1];
var page = require('webpage').create();
console.log("Opening page: " + url);
page.open(url, function (status) {
if (status !== "success") {
console.log("Unable to access network");
} else {
console.log("Setting timeout...");
window.setTimeout(function() {
page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js", function() {
console.log("Searching for Seawolf Calendar...");
console.log("h1.size=" + $('h1').size());
console.log("Exiting with status 0...");
phantom.exit(0);
});
}, 5000);
}
});
}
脚本是这样从命令行调用的,例如:
phantomjs download-framed-content.js "http://www.sonoma.edu/calendar/groups/clubs.html"
输出如下:
system.args.length=2 打开页面:http://www.sonoma.edu/calendar/groups/clubs.html 设置超时... 正在搜索海狼日历... [挂...]为什么 jQuery 调用会挂起脚本?
【问题讨论】:
-
我注意到你从不赞成你得到的答案。我不知道这是为什么。我的回答是否缺少一些信息或其他方面不好?
标签: javascript jquery phantomjs