Skip to content

Instantly share code, notes, and snippets.

@youhide
Last active June 24, 2017 04:45
Show Gist options
  • Select an option

  • Save youhide/05cb059050d68d31c7344ad9b89ede6a to your computer and use it in GitHub Desktop.

Select an option

Save youhide/05cb059050d68d31c7344ad9b89ede6a to your computer and use it in GitHub Desktop.
Google Analytics Login Crawler ( CasperJS )
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();
@youhide
Copy link
Copy Markdown
Author

youhide commented Jun 24, 2017

need update, new login form.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment