Skip to content

Instantly share code, notes, and snippets.

@ydnax
Created October 3, 2011 09:06
Show Gist options
  • Save ydnax/1258745 to your computer and use it in GitHub Desktop.
Save ydnax/1258745 to your computer and use it in GitHub Desktop.
humble keycrawler.
var urllib=require("./urllib.js");
var sys=require("sys");
var urlparser=require("url");
var spawn = require('child_process').spawn;
var starturl="http://www.google.com/search?hl=en&q=http%3A%2F%2Fwww.humblebundle.com%2F%3Fkey%3D";
var regex=/www ?\. ?humblebundle ?\. ?com ?\/\?key ?\=\w{2,13}/ig;
var hit=function(url){
//console.log("newurl: "+url);
try{
urllib.processUrl(url, function($){
var m;
try{
m=regex.exec($("html").html());
}catch(e){}
if(!m){
//console.log("nohit: "+url);
return;
}
m.input="";
//console.log("hit: "+url);
//console.log(sys.inspect(m));
console.log(m[0]);
spawn('firefox', [m[0]]);
});}catch(e){console.log("error url:"+url);};
};
var searchPage=function(url){
//console.log("nexturl"+url);https://gist
urllib.processUrl(url,
function($){
$(".r").each(function(){
hit($("a",this).attr("href"));
});//pnnext
try{
var purl=urlparser.parse(starturl);
var newurl=purl.protocol+"//"+purl.hostname+$("#pnnext").attr("href");
setTimeout(function(){searchPage(newurl)},1337)
}catch(e){}
});
};
searchPage(starturl);
var jquery=require("jquery");
var jsdom =require("jsdom");
exports.processUrl=function (url, cb){
jsdom.env({
html: url,
scripts: [],
done: function(errors, window) {
if(errors)
throw errors;
var $ = jquery.create(window);
$._X_win=window;
cb($);
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment