下载基于 Content-Type JavaScript Casperjs 的链接

Download a link based on Content-Type JavaScript Casperjs

本文关键字:Casperjs 链接 JavaScript Content-Type 下载      更新时间:2023-09-26

我是CasperJS的初学者程序员,我正在编写一个收集站点上每个链接的爬虫,我希望根据内容类型下载。

var links = this.evaluate(function() {
    var links = [];
    Array.prototype.forEach.call(__utils__.findAll('a'), function(e) {
        links.push(e.getAttribute('href'));
    });
    return links;
});
Array.prototype.forEach.call(links, function(link) {
    //get content-type of link 
    //download based on context type ie. images or text
});
casper.on("resource.received", function(response){
   "use strict";
    resourcesRec.push(response);
    var file = response.url.replace(/^.*['''/]/, '');
    casper.download(response.url,file);
});