I wrote a javascript which when used in browser such as chrome, keeps on scrolling such facebook pages in which more content is loaded as you scroll.
i = 0;
minutes = 30;
counter = minutes * 60;
function repeatScroll()
{
console.log('scrolling');
if (i < counter)
{
window.scrollTo(0, document.body.scrollHeight);
i++;
}
setTimeout(repeatScroll, 5000);
}
repeatScroll();
I wanted to do same using phantomjs, but I am unable to do so. I am doubting it has something to do with the delay, but I am unable to figure it out.
This is a snippet from my phantom js code :
var url = "https://www.facebook.com/search/965993006761563/likers";
page.open(url, function (status) {
setTimeout(function () {
page.evaluate(function () {
console.log('gooooooooooooooooo');
});
page.render("liker.png");
page.evaluate(function() {
i = 0;
minutes = 30;
counter = minutes * 60;
function repeatScroll()
{
console.log('scrolling');
if (i < counter)
{
window.scrollTo(0, document.body.scrollHeight);
i++;
}
setTimeout(repeatScroll, 5000);
}
repeatScroll();
});
Console only outputs scrolling
once. I am not sure what changes do I need to do.
After scrolling all the way through out I want to extract all profile id's too. Planning to add this just below the above code.
var title = page.evaluate(function() {
var e=document.getElementsByClassName("fsl fwb fcb");
var ids = [];
for(var i = 0 ; i < e.length; i++)
{
ids.push(JSON.parse(e[i].childNodes[0].getAttribute("data-gt")).engagement.eng_tid);
}
console.log(ids);
return ids;
});
Also, when I currently add it, I do not get any profile id output.
Edit : I already read this (How to scroll down with Phantomjs to load dynamic content) but this is not present in my case.