Initial commit.

This commit is contained in:
larruda 2014-09-07 22:06:54 -03:00
parent 939ae7762e
commit c878f90290

69
craw.js
View file

@ -24,6 +24,12 @@ LOGIN_URL = 'https://auth.api.sonyentertainmentnetwork.com/login.jsp';
FREE_GAMES_URL = 'https://store.sonyentertainmentnetwork.com/#!/en-us/free-games/cid=STORE-MSF77008-PSPLUSFREEGAMES'; FREE_GAMES_URL = 'https://store.sonyentertainmentnetwork.com/#!/en-us/free-games/cid=STORE-MSF77008-PSPLUSFREEGAMES';
FREE_TO_PLAY_URL = 'https://store.sonyentertainmentnetwork.com/#!/en-us/free-to-play/cid=STORE-MSF77008-PS3F2PPS3'; FREE_TO_PLAY_URL = 'https://store.sonyentertainmentnetwork.com/#!/en-us/free-to-play/cid=STORE-MSF77008-PS3F2PPS3';
var urls = [];
urls.push(FREE_TO_PLAY_URL);
if (casper.cli.has('psn-plus-member')) {
urls.push(FREE_GAMES_URL);
}
casper.start(LOGIN_URL, function() { casper.start(LOGIN_URL, function() {
'use strict'; 'use strict';
this.echo('Logging in...'); this.echo('Logging in...');
@ -41,45 +47,46 @@ casper.waitForUrl(/loginSuccess\.jsp$/, function() {
this.echo('Failed to login.', 'ERROR').exit(-1); this.echo('Failed to login.', 'ERROR').exit(-1);
}); });
//casper.thenOpen(FREE_GAMES_URL, function() { casper.eachThen(urls, function(response) {
casper.thenOpen(FREE_TO_PLAY_URL, function() { this.thenOpen(response.data, function(response) {
'use strict'; 'use strict';
this.echo(this.getTitle()); this.echo(this.getTitle());
casper.waitUntilVisible(".addToCartBtn", function() { casper.waitUntilVisible(".addToCartBtn", function() {
this.echo("I waited for 10 secs..."); this.echo("I waited for 10 secs...");
games = this.evaluate(function(){ games = this.evaluate(function(){
var elements = document.querySelectorAll(".cellGridGameStandard:not(.ownAlready)"); var elements = document.querySelectorAll(".cellGridGameStandard:not(.ownAlready)");
games = []; games = [];
[].forEach.call(elements, function(element, index) { [].forEach.call(elements, function(element, index) {
if (!element.classList.contains('ownAlready')) { if (!element.classList.contains('ownAlready')) {
games.push({ games.push({
'id': element.id, 'id': element.id,
'title': element.querySelector(".cellTitle").innerHTML 'title': element.querySelector(".cellTitle").innerHTML
}); });
} }
});
return games;
}); });
return games; if (games.length == 0) {
}); this.echo("No free donuts for you today, brotha!");
}
if (games.length == 0) { this.echo("Found out " + games.length + " left FREE games!");
this.echo("No free donuts for you today, brotha!");
}
this.echo("Found out " + games.length + " left FREE games!"); games.forEach(function(game, index) {
casper.echo("Title: " + game.title);
});
games.forEach(function(game, index) { this.echo('Purchasing title "' + games[0].title + '".');
casper.echo("Title: " + game.title);
});
this.echo('Purchasing title "' + games[0].title + '".');
}, function() {
this.echo("Houston, we have a problem!", 'ERROR');
}, function() { }, 15000);
this.echo("Houston, we have a problem!", 'ERROR'); });
}, 15000);
}); });
casper.then(function() { casper.then(function() {