Simple Instagram Like Bot

This is a very simple Instagram like bot written in JavaScript. It’s described in more detail in the Like Bot book where I explain the code and provide some tips on how to customize the bot for your own needs.

JavaScript Version

This script takes a little work but it’s free. Here are the steps to use the JavaScript version of this Instagram like bot.

  • Highlight and copy the entire code block below
  • Open your browser and visit intagram.com
  • Enter a hash tag in the search box
  • Open the first post under “Most Recent”
  • Open the JavaScript console in your browser
  • Paste this code into the console

The code is below. Because of frequent changes at Instagram this code is sometimes broken. In fact, this script is broken as of a recent redesign. I’ve spent a few minutes trying to adjust it but I’ve been unable to get it to work in the little time I have for it. If you manage to get it to work, let me know and I’ll update these instructions.

Instagram is also cracking down on bot use like this and there is some risk to your Instagram account. Use this script at your own risk or see the Chrome extension listed above for a safer option.

function getHeartElement() {
    var knownHeartElementNames = ["coreSpriteHeartOpen", "coreSpriteLikeHeartOpen"];
    var i = 0;
    // Loop through the known heart elements until one works
    for (i = 0; i < knownHeartElementNames.length; i++) {
        var heartElement = document.querySelector("." + knownHeartElementNames[i]);
        if (heartElement != undefined) {
            break;
        }
    }
    return heartElement;
}

function doLike() {
    var likeMax = 100;
    var likeElement = getHeartElement();
    var nextElement = document.querySelector(".coreSpriteRightPaginationArrow");
    likeCount++;
    var nextTime = Math.random() * (14000 - 4000) + 4000;
    if (likeElement.innerHTML.match("Unlike") == null) {
        likeElement.click();
        console.log(likeCount + " - liked");
    } else {
        console.log(likeCount + " - skipped");
    }
    setTimeout(function() {nextElement.click();}, 1000);
    if (likeCount < likeMax) {
        setTimeout(doLike, nextTime);
    } else {
        console.log("Nice! Time for a break.");
    }
}

var likeCount = 0;
doLike();

This code is also available in my web-bots repo on GitHub. If you’d like to contribute changes, please submit a pull request.

Opening the Console

The easiest way to open the javascript console is using the shortcut key combination. Here are the key combinations for several popular browsers.

Browser Keys
Google Chrome for Mac //command//, //option//, //J//
Firefox for Mac //command//, //option//, //K//
Safari for Mac //command//, //option//, //C//
Google Chrome for Windows //control//, //shift//, //J//
Firefox for Windows //control//, //shift//, //I//
Google Chrome for Linux //control//, //shift//, //J//
Firefox for Linux //control//, //shift//, //I//

More Information

This bot is described in more detail in the Like Bot book where I explain the code and provide some tips on how to customize the bot for your own needs. Purchases help encourage continued development of the code as it adapts to various changes.

Legacy Version

This is a similar bot written for the iMacros plugin. The plugin is available for IE, Chrome, and Firefox. This version is out of date and, although shorter, is much more complicated to use than the version above; use the JavaScript version instead.

Getting Ready

In order to run this bot you need to install the iMacros plugin for your browser platform. Here are the links for Chrome and Firefox (it’s also available for IE but you’ll have to search for that one yourself).

iMacros for Chrome
iMacros for Firefox

Running the Bot

In order to use the bot, do the following:

  • Open Instagram in your browser
  • Search for a specific tag you want
  • Click on the first image
  • Open the iMacros plugin in your browser
  • Run the bot with the “Play Loop” option

The Macro Code

iMacros scripts are stored in the browser as bookmarks, so you’ll want to save the script before you can use it. To start a new script hit “Record” and then stop. Overwrite the macro with the code below then save it with a name like “Instagram Like Bot”.

Here’s the code for the bot itself.

SET !VAR1 EVAL("var randomNumber=Math.floor(Math.random()*5 + 3); randomNumber;")
TAG POS=1 TYPE=A ATTR=TXT:Like
TAG POS=1 TYPE=A ATTR=TXT:Next
WAIT SECONDS={{!VAR1}}

Features

  • Very simple script
  • Random pauses so it acts like a human
  • You can watch it run
  • You can run it in a background tab

16 thoughts on “Simple Instagram Like Bot

  1. Hi Joel, noticed that you have just changed the first code above to what looks like a more updated version. However, it is not immediately clear for noobs like me how many times this code will run (unlike the previous code where it is clear that it will run for 25 times). I understand that the Math Random line is for duration between the loops, but how can I change how many times the loop is run? P.S. I tried changing ‘1000’ to ‘5’ but it still ran more than 5 times. Thanks.

    1. It’s the following line that tells it how many times to loop. This updated version loops 100 times by default. Be careful with this setting; if you go too high Instagram might detect you as a bot and limit your account. In my experience, the limits are temporary but don’t abuse it.

      var likeMax = 100;

    1. Sure. You could probably set an interval that runs doLike() every few hours. Here’s an example that runs it every hour. Just add this to the end of the script.

      setInterval(doLike, 3600000); // Run doLike every hour

  2. So with this macro, the thinking is its going to “like” most recent stuff that you hashtag and in doing so the people who took the photo will maybe like your stuff back?

  3. Hi!

    Instagram seems to have changed things up again, and I cant get the code to work. Any suggestions?

    Sincerely, Christian.

    1. It looks like the LikeElement is no longer a function, so the script isn’t working anymore. Returns “LikeElement is null” every time. An update would be amazing.

  4. Hi, thanks for your script!

    I inserted the following code from https://dev.to/danijelajs/javascript-instagram-bot-3nmk into your script to identify the “like” option in the current version of Insta:

    var likeElement = document.querySelector(‘article > div.eo2As > section.ltpMr.Slqrh > span.fr66n > button’);

    As for the “Like status”, I used the following: likeElement.innerHTML.match(“#ed4956”) == null

    That worked for me!

    1. Nice find! I haven’t been able to spend the time to find the updated selector; looks like you found it. I’ll give this a try a little later and update my code if I find it to work. In the meantime your comment is live on the page so others can find it.

  5. You’re my hero! Works like a charm! Thanks so much.
    It is really just those two lines that have to be changed. And when copy-pasting, I had to make sure that the ” sign was properly displayed.

Leave a Reply

Your email address will not be published. Required fields are marked *