-
-
Save chapel/614942 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var httpAgent = require('http-agent'), | |
jsdom = require('jsdom'), | |
url = require('url'), | |
sys = require('sys'); | |
exports.start = function () { | |
var agent = httpAgent.create('www.bungie.net', ['/stats/reach/playergamehistory.aspx?player=thechapel&vc=2']); | |
agent.addListener('next', function (err, agent) { | |
//console.log(agent.body); | |
var uri = url.parse(agent.url.toLowerCase()); | |
//console.log(uri); | |
exports.dispatch(uri, agent); | |
}); | |
agent.addListener('stop', function (err, agent) { | |
sys.puts('the agent has stopped'); | |
}); | |
agent.start(); | |
}; | |
exports.dispatch = function (uri, agent) { | |
switch (uri.pathname) { | |
case '/stats/reach/playergamehistory.aspx': | |
exports.playergamehistory(agent); | |
break; | |
case '/stats/reach/gamestats.aspx': | |
exports.gamestats(agent); | |
break; | |
} | |
}; | |
exports.playergamehistory = function (agent) { | |
var window = jsdom.jsdom(agent.body).createWindow(); | |
jsdom.jQueryify(window, './jquery.js', function (window, jquery) { | |
window.jQuery('a[id$=hypGame]').each(function () { | |
agent.addUrl(this.href); | |
}); | |
agent.next(); | |
}); | |
}; | |
exports.jqwindow = function(agent, selector, callback) { | |
var window = jsdom.jsdom(agent.body).createWindow(); | |
jsdom.jQueryify(window, './jquery.js', function (window, jquery) { | |
var query = []; | |
window.jQuery(selector).each(function () { | |
query.push(this.innerHTML.trim()); | |
}); | |
callback (query); | |
}); | |
} | |
exports.gamestats = function (agent) { | |
ratings = function (query) { | |
console.log(query); | |
} | |
selected = function (query) { | |
console.log(query); | |
} | |
exports.jqwindow(agent, 'td[id$=arenaRating]', ratings); | |
//ratings.sort(compare); | |
exports.jqwindow(agent, 'a[id$=gamertagHyperLink]', selected); | |
//console.log(selected.query, ratings.query); | |
agent.next(); | |
function compare(a,b){ | |
return b-a; | |
}; | |
} | |
exports.start(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment