0

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.

Community
  • 1
  • 1
Saurabh Shrivastava
  • 1,055
  • 1
  • 12
  • 26
  • why not use the graph api instead? you are not allowed to scrape on facebook anyway. also, getting page data with the graph api is a LOT easier than using phantomjs for this. – andyrandy Dec 22 '16 at 14:33
  • @l There is no way of getting list of people who have liked a page in Graph API. :( – Saurabh Shrivastava Dec 22 '16 at 17:56
  • @luschn There is no way of getting list of people who have liked a page in Graph API. :( – Saurabh Shrivastava Dec 22 '16 at 17:57
  • 1
    There is no way because there is no reason to actually get them. – WizKid Dec 22 '16 at 17:59
  • @WizKid How can you say so? I want the list of all 'fans' to say, perform a giveaway, or maybe for some other such task, then? – Saurabh Shrivastava Dec 22 '16 at 21:26
  • 1
    Perform a giveaway is not allowed. You are not allowed to give users anything just because they liked your page. Not even the chance of winning. – WizKid Dec 22 '16 at 21:51
  • @WizKid I was following these guideline http://www.shortstack.com/is-your-facebook-contest-legal-infographic/ – Saurabh Shrivastava Dec 23 '16 at 08:01
  • That is not correct. Read Facebook policies and not some third party site – WizKid Dec 23 '16 at 08:03
  • @WizKid Okay, thanks. :) But that was not the primary aim, aim was to accomplish scrolling. – Saurabh Shrivastava Dec 23 '16 at 08:12
  • Correct but I work at Facebook so I'm not going to help you to do something against our policies – WizKid Dec 23 '16 at 08:13
  • @WizKid Oh I am sorry, but I don't mean to offend any of those policies. I just want to learn automation. It was just a part of a learning process. I wanted to learn how to scroll in any website where data is dynamically loaded. For example in an ecommerce site, where in future I can write a script that will fetch the cheapest price of a, say TV set. I used example of Facebook because it is extremely common. I am sorry if I came as offender. I just wanted to learn to accomplish this using phantomjs. – Saurabh Shrivastava Dec 23 '16 at 08:19

0 Answers0