Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Casperjs script to screenshot an entire Facebook Post
// Using Casperjs to screenshot an entire Facebook Post */
var casper = require('casper').create({
clientScripts: [
//login to facebook
casper.start('', function() {
this.fill('#login_form', { email: 'email', pass: 'password' }, true);
//go to the facebook post
var thePost = "";
casper.thenOpen(thePost, function() {
console.log("At the right post");
//start loop
casper.then(function() {
//click view more posts, make screenshot
function viewMore(i) {
casper.then(function() {
//remove last 50 comments to keep the RAM fresh
this.evaluate(function() {
jQuery(function($) {
$("ul.commentList > li").slice(-50).remove();
//view more posts"input.stat_elem");
console.log("clicked view more – now capturing");
//echo where we are
//wait for the comments to load
this.wait(5000, function() {
//capture – config the clipRect to your liking!
this.capture(+i+'.png', {top:634, left:0, width: 689, height: 2233});
this.echo("captured:" + i);
//start over, take total amount of comments divided by 50 to get the stop
if(i < 25000) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment