Skip to content

Instantly share code, notes, and snippets.

@khajavi
Created March 6, 2015 13:02
Show Gist options
  • Save khajavi/4c528709bf4ad81645b2 to your computer and use it in GitHub Desktop.
Save khajavi/4c528709bf4ad81645b2 to your computer and use it in GitHub Desktop.
var http = require("http");
var phantom = require("phantom");
var util = require('util');
var url = "http://fa-ir.facebook.com/abdolkarimi.org";
var jquery = "http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js";
phantom.create(function(ph) {
ph.createPage(function(page) {
console.log(util.inspect(page))
page.open(url, function(status) {
if (status !== 'success') {
console.log('Unable to access the network!');
} else {
page.includeJs(jquery, function() {
page.evaluate(function() {
function sleep(time, callback) {
callback();
var stop = new Date().getTime();
while (new Date().getTime() < stop + time) {
;
}
}
function getDocHeight() {
var D = document;
return Math.max(D.body.scrollHeight,
D.documentElement.scrollHeight, D.body.offsetHeight,
D.documentElement.offsetHeight, D.body.clientHeight,
D.documentElement.clientHeight);
}
var try_try;
var i = 1
try_try = function() {
i = i + 1;
sleep(1000, function() {
window.scrollTo(0, getDocHeight());
})
if (i < 4)
return try_try();
}
try_try();
var links = [];
var result = $('.userContent').each(function(i, v) {
links.push($(v).html().trim());
});
return links;
}, function(data) {
// page.render('server.png')
console.log(data);
console.log(data.length)
console.log('finished')
ph.exit();
})
});
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment