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|21 Comments

21 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!

      • J September 15, 2017 at 10:36 am - Reply

        How long does it take for data to show, think I did all the steps correctly, but still shows zero data after 5-10 minutes, is that normal?

  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.

      • steph March 29, 2017 at 11:00 pm - Reply

        Hey Nicerobot, that’s quite awesome. Works like a charm. Is there a way to add number of followers for each follower? That would be cool!

  6. Ernie April 15, 2017 at 6:13 am - Reply

    It would be great if it could scrape the followers and only add them to the csv file if the follower has greater than 10 posts (for example or any number chosen) to try to filter out all the fake postless accounts out there.

    • Nice Robot May 2, 2017 at 8:40 pm - Reply

      It is possible to implement by opening each follower separately and checking their stats. Looks doable on a small scale. Robot’s running time would grow significantly.

  7. Linton April 27, 2017 at 3:21 am - Reply

    This is great, any chance there is code you’ve created to follow the accounts that are dumped into the CVS? If there is a tool out there, would appreciate someone pointing me in the right direction!
    Cheers
    LT

    • Nice Robot May 2, 2017 at 8:38 pm - Reply

      No we haven’t done such a thing. I think it would be very intrusive and not appreceated by Instagram.

  8. Liz May 2, 2017 at 8:19 pm - Reply

    Can I input a list of usernames (for example, @ibm, @nike, @instagram) and have this scraper pull the profile data for each username into a .csv. For example, username, first name, last name, # of followers, #of followings, # of posts, bio?

  9. realjay June 9, 2017 at 12:21 pm - Reply

    Helo Nice Robot, i, would like to buy this as an application on my windows7 if its possible can you reach me via email or skype? ill be waiting for you. thank you.

  10. Pololo June 14, 2017 at 11:56 pm - Reply

    Hi! This script works fine? Any changes??? thanks

  11. Tasha June 27, 2017 at 7:10 pm - Reply

    Nice Robot- not able to get this script to work. Any idea why not?

  12. Nice Robot June 27, 2017 at 9:39 pm - Reply

    Sadly, Instagram has a new website design and this robot will not work until we recreate it for the new design.

    • Tasha June 27, 2017 at 9:56 pm - Reply

      hate that- would love to use it again once it gets recreated.

Leave A Comment