Created
September 10, 2016 13:28
-
-
Save suriyadeepan/aeb5493154b09f17a598cf30a6ffb209 to your computer and use it in GitHub Desktop.
Casper sucks!!
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
casper = require('casper').create({ | |
verbose : true, | |
logLevel : 'debug', // debug, info, warning, error, | |
pageSettings: { | |
logImages : false, | |
logPlugins : false, | |
//userAgent : 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)' | |
//userAgent : 'Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19' | |
userAgent : 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.149 Safari/537.36' | |
}, | |
clientScripts : ['vendor/jquery.min.js', 'vendor/lodash.min.js'] | |
}); | |
var url = 'https://twitter.com/search?q=%23Brexit&src=tyah'; | |
var tweets = []; | |
function grabTweets(){ | |
var items = $('.tweet.js-stream-tweet'); | |
return _.map(items, function(item){ | |
return item.getAttribute('data-tweet-id'); | |
}); | |
} | |
casper.start(url, function(){ | |
this.echo('>> Started'); | |
//this.page.scrollPosition = { top: this.page.scrollPosition["top"] + document.body.scrollHeight, left: 0 }; | |
this.scrollToBottom(); | |
this.echo('>> Now we wait'); | |
this.wait(2000); | |
}); | |
casper.then(function(){ | |
tweets = this.evaluate(grabTweets); | |
}); | |
casper.run(function(){ | |
this.echo('>> ' + tweets.length + ' tweets found..'); | |
for(i=0; i < tweets.length; i++) | |
this.echo(i + ' ' + tweets[i] + '\n'); | |
this.echo('>> Terminating now..').exit(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment