Scrape Instagram Followers

Scrape Instagram Followers

Our platform is often used by growth hackers for lead generation in social media networks. One such use case is building a list of Instagram followers from interestingprofiles. Today we placed one such robot into our portal‘s demo space for anyone to use. Robot is only 30 lines of Javascript code and works quite fast. We tested it with IBM’s Instagram which has 78k followers and it took only 14 minutes to scrape them.

instagram_robot

How to use this robot:

  1. Login to Web Robots portal on Chrome browser.
  2. Make sure you have Web Robots Chrome extension to run the robot.
  3. Open robot instagram_followers in our extension.
  4. Make sure you are logged in on Instagram website.
  5. Modify start URL to the desired Instagram profile (example: https://www.instagram.com/ibm) and click Run.
  6. When robot is finished data will be available on portal in CSV and JSON formats.

Remember, this robot is placed in Demo space, which means it can be modified by anyone. In case someone messes up the code, you can restore it from code below. Just paste it into extension’s editor:

// Must be logged in
// Start URL above must be target Instagram profile. Example: https://www.instagram.com/ibm/
 
steps.start = function(req) {
 
    var user_id = $("script:contains(profilePage_)").text().split('profilePage_')[1].split('"')[0];
 
    if (!req) {
        req = "q=ig_user(" + user_id + ")+%7B%0A++followed_by.first(20)+%7B%0A++++count%2C%0A++++page_info+%7B%0A++++++end_cursor%2C%0A++++++has_next_page%0A++++%7D%2C%0A++++nodes+%7B%0A++++++id%2C%0A++++++is_verified%2C%0A++++++followed_by_viewer%2C%0A++++++requested_by_viewer%2C%0A++++++full_name%2C%0A++++++profile_pic_url%2C%0A++++++username%0A++++%7D%0A++%7D%0A%7D%0A&ref=relationships%3A%3Afollow_list";
    }
 
    var token = $("script:contains(csrf_token)").text().split('"csrf_token": "').pop().split('"').shift();
 
    $.ajax({
        url: "https://www.instagram.com/query/",
        headers: {
            'x-instagram-ajax': '1',
            "x-csrftoken": token
        },
        method: 'POST',
        data: req,
        success: function(data) {
 
            emit("Followers", data.followed_by.nodes);
 
            if (data.followed_by.page_info.has_next_page) {
                var next_req = "q=ig_user(" + user_id + ")+%7B%0A++followed_by.after(" + data.followed_by.page_info.end_cursor + "%2C+20)+%7B%0A++++count%2C%0A++++page_info+%7B%0A++++++end_cursor%2C%0A++++++has_next_page%0A++++%7D%2C%0A++++nodes+%7B%0A++++++id%2C%0A++++++is_verified%2C%0A++++++followed_by_viewer%2C%0A++++++requested_by_viewer%2C%0A++++++full_name%2C%0A++++++profile_pic_url%2C%0A++++++username%0A++++%7D%0A++%7D%0A%7D%0A&ref=relationships%3A%3Afollow_list";
                next("", "start", next_req);
            }
 
            done(1000);
        }
    });
};
By | 2017-03-27T16:25:50+00:00 June 8th, 2016|Uncategorized|9 Comments

9 Comments

  1. Lisa October 7, 2016 at 11:25 pm - Reply

    There are several errors when I put the code in the developed environment

    • nicerobot October 27, 2016 at 2:14 pm - Reply

      Hi Lisa, Thanks for pointing out. We formatted the code differently and now you can copy-paste just fine. I tested it just now. Enjoy!

  2. amira November 11, 2016 at 7:55 am - Reply

    Very useful tool, but is limited to a maximum output of 100 thousand people could leave

    • Paul November 11, 2016 at 8:09 am - Reply

      100k records limit applies to download using CSV button on portal. This limit has to be there to avoid perormance problems as portal generates file in real-time. This process uses a lot of compute resources. However this limitation is not a problem. Each successful run also generates complete CSV and JSON files for download. Files usually take several minutes to appear under the run in the “Files” section. Just refresh run results page after several minutes from run completion.

  3. RMJ February 23, 2017 at 7:19 pm - Reply

    Love this tool. Is there any way this tool can scrape followings instead of followers?

  4. Joe March 4, 2017 at 2:10 am - Reply

    When i used it, it only scraped my personal facebook not the profile I set in hte start URL

    • nicerobot March 27, 2017 at 4:25 pm - Reply

      Hi, thanks for commenting on this issue. Instagram changed their website’s internal structure. Robot is now adjusted and works! Robot code in this blog post is also up to date.

  5. craig March 27, 2017 at 12:23 am - Reply

    I have the same problem as joe
    When i used it, it only scraped my personal instagram not the profile I set in the start URL

    • nicerobot March 27, 2017 at 4:25 pm - Reply

      Hi, thanks for commenting on this issue. Instagram changed their website’s internal structure. Robot is now adjusted and works! Robot code in this blog post is also up to date.

Leave A Comment