Last active
June 24, 2017 04:45
-
-
Save youhide/05cb059050d68d31c7344ad9b89ede6a to your computer and use it in GitHub Desktop.
Google Analytics Login Crawler ( CasperJS )
This file contains 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 casper = require('casper').create(); | |
function getLinks() { | |
var links = document.querySelectorAll('a'); | |
return Array.prototype.map.call(links, function(e) { | |
return e.getAttribute('href'); | |
}); | |
} | |
casper.start('https://accounts.google.com/ServiceLogin#identifier'); | |
casper.then(function() { | |
this.echo('1 Page: ' + this.getTitle() + ' URL: ' + this.getCurrentUrl()); | |
this.fill('form#gaia_loginform', { | |
'Email': 'user@gmail.com' | |
}, true); | |
}); | |
casper.waitFor(function check() { | |
return this.evaluate(function() { | |
return getLinks().length > 2; | |
}); | |
}, function then() { | |
this.echo(JSON.stringify(getLinks())); | |
}, function timeout() {}, 10000); | |
casper.then(function() { | |
this.echo('2 Page: ' + this.getTitle() + ' URL: ' + this.getCurrentUrl()); | |
this.fill('form#gaia_loginform', { | |
'Passwd': 'userpassword' | |
}, true); | |
}); | |
casper.waitFor(function check() { | |
return this.evaluate(function() { | |
return getLinks().length > 2; | |
}); | |
}, function then() { | |
this.echo(JSON.stringify(getLinks())); | |
}, function timeout() {}, 10000); | |
casper.thenOpen('https://analytics.google.com/analytics/web/#realtime/rt-overview/property_id/', function(){ | |
this.echo('3 Page: ' + this.getTitle() + ' URL: ' + this.getCurrentUrl()); | |
}); | |
casper.run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
need update, new login form.