我已经设置了一个脚本来创建我们应用程序的网页截图。 一切都运行得很完美,直到我遇到一个带有损坏URL的图片:
"<img src='http://testserver.our.intranet/fetch/image/373e8fd2339696e2feeb680b765d626e' />"
我已经成功使用以下方法在6秒后使脚本崩溃。在此之前,它只是一直循环。
但是,是否有可能忽略网络请求(即将图像从DOM中取出),然后继续创建缩略图,而不使用该图像(或者使用一个注入的遗失图像!)
var page = require('webpage').create(),
system = require('system'),
address, output, size;
if (system.args.length < 3 || system.args.length > 5) {
phantom.exit(1);
} else {
address = system.args[1];
output = system.args[2];
page.viewportSize = { width: 640, height: 640 };
page.zoomFactor = 0.75;
page.clipRect = { top: 10, left: 0, width: 640, height: 490 };
try{
page.open(address, function (status) {
if (status !== 'success') {
console.log('Unable to load the address!');
phantom.exit();
} else {
window.setTimeout(function () {
page.render(output);
phantom.exit();
}, 200);
}
});
} finally{
setTimeout(function() {
console.log("Max execution time " + Math.round(6000) + " seconds exceeded");
phantom.exit(1);
}, 6000);
}
}