phantomjs 有配置 loadImage,
但我想要更多,
如何控制phantomjs跳过下载某种资源,
比如css等...
=====
好消息: 已添加此功能。
https://code.google.com/p/phantomjs/issues/detail?id=230
要点:
page.onResourceRequested = function(requestData, request) {
if ((/http:\/\/.+?\.css/gi).test(requestData['url']) || requestData['Content-Type'] == 'text/css') {
console.log('The url of the request is matching. Aborting: ' + requestData['url']);
request.abort();
}
};
最佳答案
已更新,正在工作!
从 PhantomJS 1.9 开始,现有的答案不起作用。您必须使用此代码:
var webPage = require('webpage');
var page = webPage.create();
page.onResourceRequested = function(requestData, networkRequest) {
var match = requestData.url.match(/wordfamily.js/g);
if (match != null) {
console.log('Request (#' + requestData.id + '): ' + JSON.stringify(requestData));
networkRequest.cancel(); // or .abort()
}
};
如果使用abort()而不是cancel(),则会触发onResourceError。
关于phantomjs - 如何控制 PhantomJS 跳过下载某种资源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9486377/