Skip to content

Instantly share code, notes, and snippets.

@kexoth
Last active December 30, 2015 02:29
Show Gist options
  • Save kexoth/7763261 to your computer and use it in GitHub Desktop.
Save kexoth/7763261 to your computer and use it in GitHub Desktop.
var node_io = require("node.io");
function methods(input){
var _methods = {
input:input,
run: function(url) {
this.getHtml(url, function(err, $) {
var items = [];
$('li.item').each(function (li){
var a = li.children.first();
var item = {
"href" : a.attribs.href,
"title" : a.attribs.title,
"img" : a.children.first().attribs.src
};
if(JSON.stringify(item) != '{}'){
items.push(item);
}
});
if(items.length > 0){
this.emit(items);
}
else {
this.skip();
}
});
},
output: function(items){
output_callback(undefined, items);
// console.log(items);
// var hrefs = [];
// for (var item in items) {
// hrefs.push(item.href);
// }
// var job = new node_io.Job({timeout:20}, methods(hrefs));
// node_io.start(job);
}
};
return _methods;
}
var options = {
timeout: 20,
max: 20,
retries: 3
};
var job = new node_io.Job(options, methods([
"http://www.istyle.eu/mk/aksesoari.html",
"http://www.istyle.eu/mk/mac.html",
"http://www.istyle.eu/mk/ipod.html",
"http://www.istyle.eu/mk/ipad.html"
]));
node_io.start(job, options, output_callback, true);
function output_callback(err, output){
var hrefs = [];
console.log(output);
output.forEach(function (item){
console.log(item);
console.log('\n');
hrefs.push(item.href);
});
var job = new node_io.Job({timeout:20}, methods(hrefs));
node_io.start(job, options);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment