Skip to content

Instantly share code, notes, and snippets.

@phpnode
Created February 18, 2011 16:12
Show Gist options
  • Save phpnode/833888 to your computer and use it in GitHub Desktop.
Save phpnode/833888 to your computer and use it in GitHub Desktop.
var nodeio = require('node.io');
var methods = {
input: false,
run: function(row) {
var self = this;
row = "elance.com http://investing.businessweek.com/research/stocks/snapshot/snapshot.asp?capId=101648 1248 517895";
var input = row.split("\t");
try {
this.getHtml(input[1], function(err, $) {
if (err) {
self.emit(input.join("\t") + "\t" + err);
return;
}
var titles = [], scores = [], output = [];
try {
//Select all titles on the page
$('a').each(function(a) {
if (a.attribs === undefined || a.attribs.href === undefined) {
return;
}
url = a.attribs.href.toLowerCase();
if (url.indexOf("//" + input[0].toLowerCase()) != -1 || url.indexOf("//www." + input[0].toLowerCase()) != -1) {
titles.push(a.fulltext);
}
});
self.emit(input.join("\t") + "\tOK\t" + titles.join(" ").replace("\t"," ").replace("\n"," ").replace("\r"," ").trim());
}
catch (e) {
self.emit(input.join("\t") + "\t" + e);
return;
}
});
}
catch (e) {
self.emit(input.join("\t") + "\t" + e);
return;
}
}
}
exports.job = new nodeio.Job({timeout:10, max: 1, retries: 1}, methods);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment