我是 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);
});
关于javascript - 下载基于Content-Type JavaScript Casperjs的链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35115782/