Last active
March 15, 2016 19:05
-
-
Save quanengineering/1611f70b16d17c35fbaa to your computer and use it in GitHub Desktop.
How to crawl with casperjs (bypass login page)
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(); | |
var url = 'https://www.getnewsmart.com/articles/80250-xiaomi-keeps-sights-on-india-has-no-ipo-timetable'; | |
casper.start(url, function() { | |
this.echo(this.getTitle()); | |
}) | |
casper.waitFor(function check() { | |
return true; | |
}, function then() { | |
this.click("#pjax-container > div.container-top-part > div > div > a.js-signin.btn.user-auth-control_btn.-login"); | |
}); | |
casper.waitForSelector('#js-sign-in', function() { | |
this.fill('#sign_in_form', { 'user[email]': '[email protected]', 'user[password]':'b1615734' }, false); | |
this.click('#sign_in_form > input.btn.btn-sign-in'); | |
}) | |
casper.waitForSelector('.logout', function() { | |
this.open(url); | |
}); | |
casper.waitForSelector('#js-article', function() { | |
var text = this.evaluate(function() { | |
return __utils__.findOne('#js-article').textContent; | |
}); | |
this.echo(text); | |
}); | |
casper.run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment