phantomjs : Go till the end of dynamically loaded Facebook page
<p>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.</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>                    i = 0;
                    minutes = 30;
                    counter = minutes * 60;
                    function repeatScroll() 
                    { 
                        console.log('scrolling');

                        if (i &lt; counter) 
                        {
                            window.scrollTo(0, document.body.scrollHeight);
                            i++;
                        } 

                        setTimeout(repeatScroll, 5000);

                    }

                    repeatScroll();</code></pre>
</div>
</div>
</p>

<p>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.</p>

<p>This is a snippet from my phantom js code : </p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><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 &lt; counter) 
                        {
                            window.scrollTo(0, document.body.scrollHeight);
                            i++;
                        } 

                        setTimeout(repeatScroll, 5000);

                    }

                    repeatScroll();

                });</code></pre>
</div>
</div>
</p>

<p>Console only outputs <code>scrolling</code> once. I am not sure what changes do I need to do.</p>

<p>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.</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>                var title = page.evaluate(function() {
                    var e=document.getElementsByClassName("fsl fwb fcb");
                    var ids = [];
                    for(var i = 0 ; i &lt; e.length; i++)
                    {
                      ids.push(JSON.parse(e[i].childNodes[0].getAttribute("data-gt")).engagement.eng_tid);
                    }
                    console.log(ids);

                    return ids;
                  });</code></pre>
</div>
</div>
</p>

<p>Also, when I currently add it, I do not get any profile id output.</p>

<p>Edit : I already read this (<a href="https://stackoverflow.com/questions/16561582/how-to-scroll-down-with-phantomjs-to-load-dynamic-content?rq=1">How to scroll down with Phantomjs to load dynamic content</a>) but this is not present in my case.</p>