diff --git a/lib/27crags.js b/lib/27crags.js index 49d6a26..533d439 100644 --- a/lib/27crags.js +++ b/lib/27crags.js @@ -15,6 +15,11 @@ var fs = require('fs'); // A csv file with column 'name' and column 'islandCrag' var resource = __dirname + '/../resources/27crags_to_island_map.csv'; +// Setup a cookie to deal with 27crags splash page money grab +var j = request.jar(); +j.setCookie(request.cookie('campaign_seen=1'), 'http://27crags.com'); +j.setCookie(request.cookie('campaign_history=1'), 'http://27crags.com'); + cragMap = {}; fs.readFile(resource, function(err, csv) { @@ -180,10 +185,6 @@ exports.searchUser= function(name, cb) { var searchResults = []; - var j = request.jar(); - var cookie = request.cookie('campaign_seen=1'); - j.setCookie(cookie, 'http://www.27crags.com'); - // Get Htmls request.get({ uri: 'http://www.27crags.com/site/search', @@ -238,7 +239,8 @@ exports.getTicks = function(userId, cb) { request.get({ uri: urls.ascentUrl, headers: headers, - encoding: 'utf8' + encoding: 'utf8', + jar: j }, this.parallel()); // 27crags hides additional data behind an AJAX request to this @@ -246,7 +248,8 @@ exports.getTicks = function(userId, cb) { request.get({ uri: urls.moreUrl, headers: _.extend(headers, {'X-Requested-With': 'XMLHttpRequest'}), - encoding: 'utf8' + encoding: 'utf8', + jar: j }, this.parallel()); }, @@ -280,7 +283,8 @@ exports.scrapeCrags = function(start, end, cb) { request.get({ uri: 'http://www.27crags.com/crags/all/descending/by/favourite_count/page/' + number, headers: headers, - encoding: 'utf8' + encoding: 'utf8', + jar: j }, this); }, function requestEachCrag(err, resp, body) { @@ -305,6 +309,7 @@ exports.scrapeCrags = function(start, end, cb) { uri: 'http://www.27crags.com/' + $a.attr('href'), headers: headers, encoding: 'utf8', + jar: j }, function(err, res) { cbs[idx](err, res); idx++; diff --git a/tests/test.js b/tests/test.js index 9f54d60..b9e905d 100755 --- a/tests/test.js +++ b/tests/test.js @@ -2,9 +2,11 @@ var lib27crags = require('../lib/27crags'); +/* lib27crags.searchUser('bill', function(err, res) { console.log(err, res); }); +*/ lib27crags.getTicks('wmmurray', function(err, res) { //console.log(err, res.length);