【发布时间】:2016-05-09 00:48:16
【问题描述】:
我是 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
});
【问题讨论】:
-
也许您可以使用
"resource.requested"事件来查找您想要的内容类型和abort()其他所有类型 (example with"page.resource.requested")。当你解决它时,你可以回答你自己的问题。 -
当我添加函数 page.resource.requested - 我收到错误'(节点)警告:检测到可能的 EventEmitter 内存泄漏。添加了 %d 个侦听器。使用emitter.setMaxListeners() 增加限制。 11'
标签: javascript download casperjs content-type