// conveniently, wikipedia includes jQuery function visit(slug) { // avoid infinite loops! if (history.indexOf(slug) != -1) return; // remember this page history.push(slug); jQuery.ajax("http://en.wikipedia.org/wiki/"+slug, { success: // callback function(reply) { // do some processing to try to skip to the content reply = reply.substring(reply.indexOf("toctitle")); reply = reply.substring(reply.indexOf("")); reply = reply.substring(reply.indexOf("
")); // get the first link to not a file reply = reply.match(/href=['"]\/wiki\/(?!File:)([^'"]*)['"]/)[1]; console.log(reply); visit(reply); } }); } var history; function startAt(initialSlug) { history = []; visit(initialSlug); } startAt("Cheese");