How to make instagram followers bot
How to Make an Instagram Bot With Python and InstaPy – Real Python
What do SocialCaptain, Kicksta, Instavast, and many other companies have in common? They all help you reach a greater audience, gain more followers, and get more likes on Instagram while you hardly lift a finger. They do it all through automation, and people pay them a good deal of money for it. But you can do the same thing—for free—using InstaPy!
In this tutorial, you’ll learn how to build a bot with Python and InstaPy, a library by Tim Großmann which automates your Instagram activities so that you gain more followers and likes with minimal manual input. Along the way, you’ll learn about browser automation with Selenium and the Page Object Pattern, which together serve as the basis for InstaPy.
In this tutorial, you’ll learn:
- How Instagram bots work
- How to automate a browser with Selenium
- How to use the Page Object Pattern for better readability and testability
- How to build an Instagram bot with InstaPy
You’ll begin by learning how Instagram bots work before you build one.
Important: Make sure you check Instagram’s Terms of Use before implementing any kind of automation or scraping techniques.
Free Bonus: 5 Thoughts On Python Mastery, a free course for Python developers that shows you the roadmap and the mindset you’ll need to take your Python skills to the next level.
How Instagram Bots Work
How can an automation script gain you more followers and likes? Before answering this question, think about how an actual person gains more followers and likes.
They do it by being consistently active on the platform. They post often, follow other people, and like and leave comments on other people’s posts. Bots work exactly the same way: They follow, like, and comment on a consistent basis according to the criteria you set.
The better the criteria you set, the better your results will be. You want to make sure you’re targeting the right groups because the people your bot interacts with on Instagram will be more likely to interact with your content.
For example, if you’re selling women’s clothing on Instagram, then you can instruct your bot to like, comment on, and follow mostly women or profiles whose posts include hashtags such as #beauty
, #fashion
, or #clothes
. This makes it more likely that your target audience will notice your profile, follow you back, and start interacting with your posts.
How does it work on the technical side, though? You can’t use the Instagram Developer API since it is fairly limited for this purpose. Enter browser automation. It works in the following way:
- You serve it your credentials.
- You set the criteria for who to follow, what comments to leave, and which type of posts to like.
- Your bot opens a browser, types in
https://instagram.com
on the address bar, logs in with your credentials, and starts doing the things you instructed it to do.
Next, you’ll build the initial version of your Instagram bot, which will automatically log in to your profile. Note that you won’t use InstaPy just yet.
Remove ads
How to Automate a Browser
For this version of your Instagram bot, you’ll be using Selenium, which is the tool that InstaPy uses under the hood.
First, install Selenium. During installation, make sure you also install the Firefox WebDriver since the latest version of InstaPy dropped support for Chrome. This also means that you need the Firefox browser installed on your computer.
Now, create a Python file and write the following code in it:
1from time import sleep 2from selenium import webdriver 3 4browser = webdriver.Firefox() 5 6browser.get('https://www.instagram.com/') 7 8sleep(5) 9 10browser.close()
Run the code and you’ll see that a Firefox browser opens and directs you to the Instagram login page. Here’s a line-by-line breakdown of the code:
- Lines 1 and 2 import
sleep
andwebdriver
. - Line 4 initializes the Firefox driver and sets it to
browser
. - Line 6 types
https://www.instagram.com/
on the address bar and hits Enter. - Line 8 waits for five seconds so you can see the result. Otherwise, it would close the browser instantly.
- Line 10 closes the browser.
This is the Selenium version of Hello, World
. Now you’re ready to add the code that logs in to your Instagram profile. But first, think about how you would log in to your profile manually. You would do the following:
- Go to
https://www.instagram.com/
. - Click the login link.
- Enter your credentials.
- Hit the login button.
The first step is already done by the code above. Now change it so that it clicks on the login link on the Instagram home page:
1from time import sleep 2from selenium import webdriver 3 4browser = webdriver. Firefox() 5browser.implicitly_wait(5) 6 7browser.get('https://www.instagram.com/') 8 9login_link = browser.find_element_by_xpath("//a[text()='Log in']") 10login_link.click() 11 12sleep(5) 13 14browser.close()
Note the highlighted lines:
- Line 5 sets five seconds of waiting time. If Selenium can’t find an element, then it waits for five seconds to allow everything to load and tries again.
- Line 9 finds the element
<a>
whose text is equal toLog in
. It does this using XPath, but there are a few other methods you could use. - Line 10 clicks on the found element
<a>
for the login link.
Run the script and you’ll see your script in action. It will open the browser, go to Instagram, and click on the login link to go to the login page.
On the login page, there are three important elements:
- The username input
- The password input
- The login button
Next, change the script so that it finds those elements, enters your credentials, and clicks on the login button:
1from time import sleep 2from selenium import webdriver 3 4browser = webdriver. Firefox() 5browser.implicitly_wait(5) 6 7browser.get('https://www.instagram.com/') 8 9login_link = browser.find_element_by_xpath("//a[text()='Log in']") 10login_link.click() 11 12sleep(2) 13 14username_input = browser.find_element_by_css_selector("input[name='username']") 15password_input = browser.find_element_by_css_selector("input[name='password']") 16 17username_input.send_keys("<your username>") 18password_input.send_keys("<your password>") 19 20login_button = browser.find_element_by_xpath("//button[@type='submit']") 21login_button.click() 22 23sleep(5) 24 25browser.close()
Here’s a breakdown of the changes:
- Line 12 sleeps for two seconds to allow the page to load.
- Lines 14 and 15 find username and password inputs by CSS. You could use any other method that you prefer.
- Lines 17 and 18 type your username and password in their respective inputs. Don’t forget to fill in
<your username>
and<your password>
! - Line 20 finds the login button by XPath.
- Line 21 clicks on the login button.
Run the script and you’ll be automatically logged in to to your Instagram profile.
You’re off to a good start with your Instagram bot. If you were to continue writing this script, then the rest would look very similar. You would find the posts that you like by scrolling down your feed, find the like button by CSS, click on it, find the comments section, leave a comment, and continue.
The good news is that all of those steps can be handled by InstaPy. But before you jump into using Instapy, there is one other thing that you should know about to better understand how InstaPy works: the Page Object Pattern.
Remove ads
How to Use the Page Object Pattern
Now that you’ve written the login code, how would you write a test for it? It would look something like the following:
def test_login_page(browser): browser. get('https://www.instagram.com/accounts/login/') username_input = browser.find_element_by_css_selector("input[name='username']") password_input = browser.find_element_by_css_selector("input[name='password']") username_input.send_keys("<your username>") password_input.send_keys("<your password>") login_button = browser.find_element_by_xpath("//button[@type='submit']") login_button.click() errors = browser.find_elements_by_css_selector('#error_message') assert len(errors) == 0
Can you see what’s wrong with this code? It doesn’t follow the DRY principle. That is, the code is duplicated in both the application and the test code.
Duplicating code is especially bad in this context because Selenium code is dependent on UI elements, and UI elements tend to change. When they do change, you want to update your code in one place. That’s where the Page Object Pattern comes in.
With this pattern, you create page object classes for the most important pages or fragments that provide interfaces that are straightforward to program to and that hide the underlying widgetry in the window. With this in mind, you can rewrite the code above and create a HomePage
class and a LoginPage
class:
from time import sleep class LoginPage: def __init__(self, browser): self.browser = browser def login(self, username, password): username_input = self.browser.find_element_by_css_selector("input[name='username']") password_input = self.browser.find_element_by_css_selector("input[name='password']") username_input.send_keys(username) password_input.send_keys(password) login_button = browser.find_element_by_xpath("//button[@type='submit']") login_button.click() sleep(5) class HomePage: def __init__(self, browser): self.browser = browser self.browser.get('https://www.instagram.com/') def go_to_login_page(self): self.browser.find_element_by_xpath("//a[text()='Log in']").click() sleep(2) return LoginPage(self.browser)
The code is the same except that the home page and the login page are represented as classes. The classes encapsulate the mechanics required to find and manipulate the data in the UI. That is, there are methods and accessors that allow the software to do anything a human can.
One other thing to note is that when you navigate to another page using a page object, it returns a page object for the new page. Note the returned value of go_to_log_in_page()
. If you had another class called FeedPage
, then login()
of the LoginPage
class would return an instance of that: return FeedPage()
.
Here’s how you can put the Page Object Pattern to use:
from selenium import webdriver browser = webdriver.Firefox() browser.implicitly_wait(5) home_page = HomePage(browser) login_page = home_page.go_to_login_page() login_page.login("<your username>", "<your password>") browser.close()
It looks much better, and the test above can now be rewritten to look like this:
def test_login_page(browser): home_page = HomePage(browser) login_page = home_page. go_to_login_page() login_page.login("<your username>", "<your password>") errors = browser.find_elements_by_css_selector('#error_message') assert len(errors) == 0
With these changes, you won’t have to touch your tests if something changes in the UI.
For more information on the Page Object Pattern, refer to the official documentation and to Martin Fowler’s article.
Now that you’re familiar with both Selenium and the Page Object Pattern, you’ll feel right at home with InstaPy. You’ll build a basic bot with it next.
Note: Both Selenium and the Page Object Pattern are widely used for other websites, not just for Instagram.
How to Build an Instagram Bot With InstaPy
In this section, you’ll use InstaPy to build an Instagram bot that will automatically like, follow, and comment on different posts. First, you’ll need to install InstaPy:
$ python3 -m pip install instapy
This will install instapy
in your system.
Note: The best practice is to use virtual environments for every project so that the dependencies are isolated.
Remove ads
Essential Features
Now you can rewrite the code above with InstaPy so that you can compare the two options. First, create another Python file and put the following code in it:
from instapy import InstaPy InstaPy(username="<your_username>", password="<your_password>").login()
Replace the username and password with yours, run the script, and voilà! With just one line of code, you achieved the same result.
Even though your results are the same, you can see that the behavior isn’t exactly the same. In addition to simply logging in to your profile, InstaPy does some other things, such as checking your internet connection and the status of the Instagram servers. This can be observed directly on the browser or in the logs:
INFO [2019-12-17 22:03:19] [username] -- Connection Checklist [1/3] (Internet Connection Status) INFO [2019-12-17 22:03:20] [username] - Internet Connection Status: ok INFO [2019-12-17 22:03:20] [username] - Current IP is "17. 283.46.379" and it's from "Germany/DE" INFO [2019-12-17 22:03:20] [username] -- Connection Checklist [2/3] (Instagram Server Status) INFO [2019-12-17 22:03:26] [username] - Instagram WebSite Status: Currently Up
Pretty good for one line of code, isn’t it? Now it’s time to make the script do more interesting things than just logging in.
For the purpose of this example, assume that your profile is all about cars, and that your bot is intended to interact with the profiles of people who are also interested in cars.
First, you can like some posts that are tagged #bmw
or #mercedes
using like_by_tags()
:
1from instapy import InstaPy 2 3session = InstaPy(username="<your_username>", password="<your_password>") 4session.login() 5session.like_by_tags(["bmw", "mercedes"], amount=5)
Here, you gave the method a list of tags to like and the number of posts to like for each given tag. In this case, you instructed it to like ten posts, five for each of the two tags. But take a look at what happens after you run the script:
INFO [2019-12-17 22:15:58] [username] Tag [1/2] INFO [2019-12-17 22:15:58] [username] --> b'bmw' INFO [2019-12-17 22:16:07] [username] desired amount: 14 | top posts [disabled]: 9 | possible posts: 43726739 INFO [2019-12-17 22:16:13] [username] Like# [1/14] INFO [2019-12-17 22:16:13] [username] https://www.instagram.com/p/B6MCcGcC3tU/ INFO [2019-12-17 22:16:15] [username] Image from: b'mattyproduction' INFO [2019-12-17 22:16:15] [username] Link: b'https://www.instagram.com/p/B6MCcGcC3tU/' INFO [2019-12-17 22:16:15] [username] Description: b'Mal etwas anderes \xf0\x9f\x91\x80\xe2\x98\xba\xef\xb8\x8f Bald ist das komplette Video auf YouTube zu finden (n\xc3\xa4here Infos werden folgen). Vielen Dank an @patrick_jwki @thehuthlife und @christic_ f\xc3\xbcr das bereitstellen der Autos \xf0\x9f\x94\xa5\xf0\x9f\x98\x8d#carporn#cars#tuning#bagged#bmw#m2#m2competition#focusrs#ford#mk3#e92#m3#panasonic#cinematic#gh5s#dji#roninm#adobe#videography#music#bimmer#fordperformance#night#shooting#' INFO [2019-12-17 22:16:15] [username] Location: b'K\xc3\xb6ln, Germany' INFO [2019-12-17 22:16:51] [username] --> Image Liked! INFO [2019-12-17 22:16:56] [username] --> Not commented INFO [2019-12-17 22:16:57] [username] --> Not following INFO [2019-12-17 22:16:58] [username] Like# [2/14] INFO [2019-12-17 22:16:58] [username] https://www. instagram.com/p/B6MDK1wJ-Kb/ INFO [2019-12-17 22:17:01] [username] Image from: b'davs0' INFO [2019-12-17 22:17:01] [username] Link: b'https://www.instagram.com/p/B6MDK1wJ-Kb/' INFO [2019-12-17 22:17:01] [username] Description: b'Someone said cloud? \xf0\x9f\xa4\x94\xf0\x9f\xa4\xad\xf0\x9f\x98\x88 \xe2\x80\xa2\n\xe2\x80\xa2\n\xe2\x80\xa2\n\xe2\x80\xa2\n#bmw #bmwrepost #bmwm4 #bmwm4gts #f82 #bmwmrepost #bmwmsport #bmwmperformance #bmwmpower #bmwm4cs #austinyellow #davs0 #mpower_official #bmw_world_ua #bimmerworld #bmwfans #bmwfamily #bimmers #bmwpost #ultimatedrivingmachine #bmwgang #m3f80 #m5f90 #m4f82 #bmwmafia #bmwcrew #bmwlifestyle' INFO [2019-12-17 22:17:34] [username] --> Image Liked! INFO [2019-12-17 22:17:37] [username] --> Not commented INFO [2019-12-17 22:17:38] [username] --> Not following
By default, InstaPy will like the first nine top posts in addition to your amount
value. In this case, that brings the total number of likes per tag to fourteen (nine top posts plus the five you specified in amount
).
Also note that InstaPy logs every action it takes. As you can see above, it mentions which post it liked as well as its link, description, location, and whether the bot commented on the post or followed the author.
You may have noticed that there are delays after almost every action. That’s by design. It prevents your profile from getting banned on Instagram.
Now, you probably don’t want your bot liking inappropriate posts. To prevent that from happening, you can use set_dont_like()
:
from instapy import InstaPy session = InstaPy(username="<your_username>", password="<your_password>") session.login() session.like_by_tags(["bmw", "mercedes"], amount=5) session.set_dont_like(["naked", "nsfw"])
With this change, posts that have the words naked
or nsfw
in their descriptions won’t be liked. You can flag any other words that you want your bot to avoid.
Next, you can tell the bot to not only like the posts but also to follow some of the authors of those posts. You can do that with set_do_follow()
:
from instapy import InstaPy session = InstaPy(username="<your_username>", password="<your_password>") session.login() session.like_by_tags(["bmw", "mercedes"], amount=5) session.set_dont_like(["naked", "nsfw"]) session.set_do_follow(True, percentage=50)
If you run the script now, then the bot will follow fifty percent of the users whose posts it liked. As usual, every action will be logged.
You can also leave some comments on the posts. There are two things that you need to do. First, enable commenting with set_do_comment()
:
from instapy import InstaPy session = InstaPy(username="<your_username>", password="<your_password>") session.login() session.like_by_tags(["bmw", "mercedes"], amount=5) session.set_dont_like(["naked", "nsfw"]) session.set_do_follow(True, percentage=50) session.set_do_comment(True, percentage=50)
Next, tell the bot what comments to leave with set_comments()
:
from instapy import InstaPy session = InstaPy(username="<your_username>", password="<your_password>") session. login() session.like_by_tags(["bmw", "mercedes"], amount=5) session.set_dont_like(["naked", "nsfw"]) session.set_do_follow(True, percentage=50) session.set_do_comment(True, percentage=50) session.set_comments(["Nice!", "Sweet!", "Beautiful :heart_eyes:"])
Run the script and the bot will leave one of those three comments on half the posts that it interacts with.
Now that you’re done with the basic settings, it’s a good idea to end the session with end()
:
from instapy import InstaPy session = InstaPy(username="<your_username>", password="<your_password>") session.login() session.like_by_tags(["bmw", "mercedes"], amount=5) session.set_dont_like(["naked", "nsfw"]) session.set_do_follow(True, percentage=50) session.set_do_comment(True, percentage=50) session.set_comments(["Nice!", "Sweet!", "Beautiful :heart_eyes:"]) session.end()
This will close the browser, save the logs, and prepare a report that you can see in the console output.
Remove ads
Additional Features in InstaPy
InstaPy is a sizable project that has a lot of thoroughly documented features. The good news is that if you’re feeling comfortable with the features you used above, then the rest should feel pretty similar. This section will outline some of the more useful features of InstaPy.
Quota Supervisor
You can’t scrape Instagram all day, every day. The service will quickly notice that you’re running a bot and will ban some of its actions. That’s why it’s a good idea to set quotas on some of your bot’s actions. Take the following for example:
session.set_quota_supervisor(enabled=True, peak_comments_daily=240, peak_comments_hourly=21)
The bot will keep commenting until it reaches its hourly and daily limits. It will resume commenting after the quota period has passed.
Headless Browser
This feature allows you to run your bot without the GUI of the browser. This is super useful if you want to deploy your bot to a server where you may not have or need the graphical interface. It’s also less CPU intensive, so it improves performance. You can use it like so:
session = InstaPy(username='test', password='test', headless_browser=True)
Note that you set this flag when you initialize the InstaPy
object.
Using AI to Analyze Posts
Earlier you saw how to ignore posts that contain inappropriate words in their descriptions. What if the description is good but the image itself is inappropriate? You can integrate your InstaPy bot with ClarifAI, which offers image and video recognition services:
session.set_use_clarifai(enabled=True, api_key='<your_api_key>') session.clarifai_check_img_for(['nsfw'])
Now your bot won’t like or comment on any image that ClarifAI considers NSFW. You get 5,000 free API-calls per month.
Relationship Bounds
It’s often a waste of time to interact with posts by people who have a lot of followers. In such cases, it’s a good idea to set some relationship bounds so that your bot doesn’t waste your precious computing resources:
session.set_relationship_bounds(enabled=True, max_followers=8500)
With this, your bot won’t interact with posts by users who have more than 8,500 followers.
For many more features and configurations in InstaPy, check out the documentation.
Conclusion
InstaPy allows you to automate your Instagram activities with minimal fuss and effort. It’s a very flexible tool with a lot of useful features.
In this tutorial, you learned:
- How Instagram bots work
- How to automate a browser with Selenium
- How to use the Page Object Pattern to make your code more maintainable and testable
- How to use InstaPy to build a basic Instagram bot
Read the InstaPy documentation and experiment with your bot a little bit. Soon you’ll start getting new followers and likes with a minimal amount of effort. I gained a few new followers myself while writing this tutorial. If you prefer video tutorials, there is also a Udemy course by the creator of InstaPy Tim Großmann.
You can also explore the possibilities of ChatterBot, Tweepy, Discord, and Alexa Skills to learn more about how you can make bots for different platforms using Python.
If there’s anything you’d like to ask or share, then please reach out in the comments below.
Increase your Instagram followers with a simple Python bot | by Fábio Neves
I got around 500 real followers in 4 days!
Picture taken by me — Ho Chi Minh CityGrowing an audience is an expensive and painful task. And if you’d like to build an audience that’s relevant to you, and shares common interests, that’s even more difficult. I always saw Instagram has a great way to promote my photos, but I never had more than 380 followers. .. Every once in a while, I decide to start posting my photos on Instagram again, and I manage to keep posting regularly for a while, but it never lasts more than a couple of months, and I don’t have many followers to keep me motivated and engaged.
The objective of this project is to build a bigger audience and as a plus, maybe drive some traffic to my website where I sell my photos!
A year ago, on my last Instagram run, I got one of those apps that lets you track who unfollowed you. I was curious because in a few occasions my number of followers dropped for no apparent reason. After some research, I realized how some users basically crawl for followers. They comment, like and follow people — looking for a follow back. Only to unfollow them again in the next days.
I can’t say this was a surprise to me, that there were bots in Instagram… It just made me want to build one myself!
And that is why we’re here, so let’s get to it! I came up with a simple bot in Python, while I was messing around with Selenium and trying to figure out some project to use it. Simply put, Selenium is like a browser you can interact with very easily in Python.
Ideally, increasing my Instagram audience will keep me motivated to post regularly. As an extra, I included my website in my profile bio, where people can buy some photos. I think it is a bit of a stretch, but who knows?! My sales are basically zero so far, so it should be easy to track that conversion!
If you would like to have access to my other web scraping articles — and pretty much everything else on Medium — have you considered subscribing? You would be supporting my work tremendously!
Read every story on Medium!
As a Medium member, a portion of your membership fee goes to writers you read, and you get full access to every story…
medium.com
Just what the world needed! Another Instagram bot…
After giving this project some thought, my objective was to increase my audience with relevant people. I want to get followers that actually want to follow me and see more of my work. It’s very easy to come across weird content in the most used hashtags, so I’ve planed this bot to lookup specific hashtags and interact with the photos there. This way, I can be very specific about what kind of interests I want my audience to have. For instance, I really like long exposures, so I can target people who use that hashtag and build an audience around this kind of content. Simple and efficient!
My gallery is a mix of different subjects and styles, from street photography to aerial photography, and some travel photos too. Since it’s my hometown, I also have lots of Lisbon images there. These will be the main topics I’ll use in the hashtags I want to target.
This is not a “get 1000 followers in 24 hours” kind of bot!
So what kind of numbers are we talking about?
I ran the bot a few times in a few different hashtags like “travelblogger”, “travelgram”, “lisbon”, “dronephotography”. In the course of three days I went from 380 to 800 followers. Lots of likes, comments and even some organic growth (people that followed me but were not followed by the bot).
To be clear, I’m not using this bot intensively, as Instagram will stop responding if you run it too fast. It needs to have some sleep commands in between the actions, because after some comments and follows in a short period of time, Instagram stops responding and the bot crashes.
You will be logged into your account, so I’m almost sure that Instagram can know you’re doing something weird if you speed up the process. And most importantly, after doing this for a dozen hashtags, it just gets harder to find new users in the same hashtags. You will need to give it a few days to refresh the user base there.
But I don’t want to follow so many people in the process…
The most efficient way to get followers in Instagram (apart from posting great photos!) is to follow people. And this bot worked really well for me because I don’t care if I follow 2000 people to get 400 followers.
The bot saves a list with all the users that were followed while it was running, so someday I may actually do something with this list. For instance, I can visit each user profile, evaluate how many followers or posts they have, and decide if I want to keep following them. Or I can get the first picture in their gallery and check its date to see if they are active users.
If we remove the follow action from the bot, I can assure you the growth rate will suffer, as people are less inclined to follow based on a single like or comment.
Why will you share your code?!
That’s the debate I had with myself. Even though I truly believe in giving back to the community (I still learn a lot from it too!), there are several paid platforms that do more or less the same as this project. Some are shady, some are used by celebrities. The possibility of starting a similar platform myself, is not off the table yet, so why make the code available?
With that in mind, I decided to add an extra level of difficulty to the process, so I was going to post the code below as an image. I wrote “was”, because meanwhile, I’ve realized the image I’m getting is low quality. Which in turn made me reconsider and post the gist. I’m that nice! The idea behind the image was that if you really wanted to use it, you would have to type the code yourself. And that was my way of limiting the use of this tool to people that actually go through the whole process to create it and maybe even improve it.
I learn a lot more when I type the code myself, instead of copy/pasting scripts. I hope you feel the same way!
The script isn’t as sophisticated as it could be, and I know there’s lots of room to improve it. But hey… it works! I have other projects I want to add to my portfolio, so my time to develop it further is rather limited. Nevertheless, I will try to update this article if I dig deeper.
This is the last subtitle!
You’ll need Python (I’m using Python 3.7), Selenium, a browser (in my case I’ll be using Chrome) and… obviously, an Instagram account! Quick overview regarding what the bot will do:
- Open a browser and login with your credentials
- For every hashtag in the hashtag list, it will open the page and click the first picture to open it
- It will then like, follow, comment and move to the next picture, in a 200 iterations loop (number can be adjusted)
- Saves a list with all the users you followed using the bot
If you reached this paragraph, thank you! You totally deserve to collect your reward! If you find this useful for your profile/brand in any way, do share your experience below :)
In order to use chrome with Selenium, you need to install chromedriver. It’s a fairly simple process and I had no issues with it. Simply install and replace the path above. Once you do that, our variable webdriver will be our Chrome tab.
In cell number 3 you should replace the strings with your own username and the respective password. This is for the bot to type it in the fields displayed. You might have already noticed that when running cell number 2, Chrome opened a new tab. After the password, I’ll define the login button as an object, and in the following line, I click it.
If you’re wondering what those weird strings are, don’t be scared! On my article about web scraping a real estate website, I’ve been through a similar task, which consisted in inspecting the web pages in order to tell the bot where to look. You can do that very easily, simply by right clicking the element you want to map, and selecting Inspect.
Once you get in inspect mode find the bit of html code that corresponds to what you want to map. Right click it and hover over Copy. You will see that you have some options regarding how you want it to be copied. I used a mix of XPath and css selectors throughout the code (it’s visible in the find_element_ method). It took me a while to get all the references to run smoothly. At points, the css or the xpath directions would fail, but as I adjusted the sleep times, everything started running smoothly.
In this case, I selected “copy selector” and pasted it inside a find_element_ method (cell number 3). It will get you the first result it finds. If it was find_elements_, all elements would be retrieved and you could specify which to get.
Once you get that done, time for the loop. You can add more hashtags in the hashtag_list. If you run it for the first time, you still don’t have a file with the users you followed, so you can simply create prev_user_list as an empty list.
Once you run it once, it will save a csv file with a timestamp with the users it followed. That file will serve as the prev_user_list on your second run. Simple and easy to keep track of what the bot does.
Update with the latest timestamp on the following runs and you get yourself a series of csv backlogs for every run of the bot.
The code is really simple. If you have some basic notions of Python you can probably pick it up quickly. I’m no Python ninja and I was able to build it, so I guess that if you read this far, you are good to go!
The print statement inside the loop is the way I found to be able to have a tracker that lets me know at what iteration the bot is all the time. It will print the hashtag it’s in, the number of the iteration, and the random number generated for the comment action. I decided not to post comments in every page, so I added three different comments and a random number between 1 and 10 that would define if there was any comment at all, or one of the three. The loop ends, we append the new_followed users to the previous users “database” and saves the new file with the timestamp. You should also get a small report.
And that’s it!
After a few hours without checking the phone, these were the numbers I was getting. I definitely did not expect it to do so well! In about 4 days since I started testing it, I had around 500 new followers, which means I have doubled my audience in a matter of days. I’m curious to see how many of these new followers I will lose in the next few days, to see if the growth can be sustainable. I also had a lot more “likes” in my latest photos, but I guess that’s even more expected than the follow backs.
I didn’t get the screenshot at the exact start of the bot, but you get the idea!It would be nice to get this bot running on a server, but I have other projects I want to explore, and configuring a server is not one of them! Feel free to leave a comment below, and I’ll do my best to answer your questions.
If you want to get more serious about this subject, I strongly recommend these books:
- Web Scraping with Python — https://amzn. to/3QRGzYt
- Practical Web Scraping — https://amzn.to/3cyRVli
Thanks for reading! If you liked this article, I invite you to check my other stories. I’m mainly interested in Data Science, Python, Blockchain and digital currencies, technology, and a few other things like photography!
If you’d like to get in touch, you can contact me here or simply reply to the article below.
Disclosure: Some of the links in this article are affiliate links. This means that, at zero cost to you, I will earn an affiliate commission if you finalize your purchase through the link!
Create an Instagram chatbot for free | SendPulse
Convert Instagram Followers into Loyal Customers
How to Set Up an Instagram Chatbot Marketing with SendPulse Features
Promote Your Instagram Direct Chatbot with Ads
Promote Your Products and Services with an Instagram Bot , and to attract users to it, launch targeted ads with the goal of "Instagram Direct". Set up a welcome message in your Facebook ads account and add chain triggers to it. The user will select the answer that is relevant to him and go through the message chain. And if you need advice, connect the manager to the correspondence.
Accept payment
Everything for effective work with chats on Instagram
Create a bot for Instagram
Instagram Chatbot Management Mobile App
Reply to your followers using the mobile app so you can manage multiple chats and manage your chatbot on the go.
FAQ
How to Create a Chatbot on Instagram
It's easy. Log into your SendPulse account, go to the Chatbots section, and connect your Instagram page to set up your chatbot.
Who needs a chatbot on Instagram and why
Chatbot is useful for any business. If you accept and process dozens and hundreds of direct orders and receive the same questions from leads and customers every day, delegate these tasks to a chatbot. Thus, you do not have to hire a person to work with Direct, because these routine processes can be easily automated.
How Instagram Chatbot Works
You need to pre-write chatbot scripts for various subscriber actions, for example, placing an order, exchanging, returning, answering frequently asked questions. Now, every time the user performs the target action, the chatbot will automatically respond to him according to your scenario without your participation. It will also send customer data to CRM and sort by the filter you set.
What are the benefits of an Instagram chatbot
By creating a chatbot, you do not have to hire an order processing manager in direct, which can significantly save your budget. The chatbot works 24/7 and seven days a week, which provides an instant response to each user. Consequently, you will be able to increase the number of sales, since the buyer will not have to look for another store where they will respond faster.
How to set up welcome and other automatic message threads
To set up an automatic message thread, first set the desired trigger for sending it - this can be a keyword that the user writes in a chat or a specific event, such as a subscription to a page. Next, write down the message script and sending conditions for each auto-reply.
How to invite managers to your SendPulse account for teamwork
Go to "Account Settings" in the "Users" tab and click "Invite User". Read detailed instructions on granting access to your SendPulse account.
For what other social networks can I set up a bot in SendPulse
With SendPulse Chatbot Builder you can set up bots for WhatsApp, Facebook, Instagram and Telegram.
How to find out the prices for the chatbot service in SendPulse
Check out the tariff scale on the pricing page for the chatbot service for messengers.
Connect the bot to Instagram and free yourself from routine answers
Create a bot to provide 24/7 interaction with your audience on Instagram
Connect for free
How to create an Instagram chatbot for business
The number of Instagram users in the world exceeds 1.22 billion people, the Russian audience is estimated at 56 million. 83% of social network users learn about new products and services through it, and 80% make a purchase decision based on information in their account.
In order not to miss an order, you need to be ready to respond to inquiries from potential customers at any time and respond as quickly as possible. This is where Instagram chatbots can help you — we have finally implemented this feature in SendPulse.
- What is a chatbot on Instagram
- What business problems does a chatbot solve?
- FAQ
- Automation of part of the processes in the sales funnel
- Engage subscribers, increase trust
- Targeted mailings
- Reminders
- Collecting Feedback
- Saving user data
- Reaction to the mark in the story
- API request to get data from external sources
- Examples of chatbots on Instagram
- How to Create an Instagram Chatbot with SendPulse
- Connecting Instagram
- Interface
- Launching auto-replies and chatbot message threads
- Trigger "Welcome Series"
- Trigger "Standard Response"
- Bot Unfollow Trigger
- Creating your own trigger
- All the features of the SendPulse Chatbot Builder
- Block "Message"
- Continuation of the chain
- Block "Action"
- Filter block
- API request block
- Block "Pause"
- Block "Random choice"
- Additional features of chatbots in SendPulse
- Bot message segmentation
- Subscription Widget
- live chat
- An example of building a chatbot for Instagram in SendPulse
- Setting up the starting block
- Create the following messages
- Conclusion
What is a chatbot on Instagram
A chatbot is a virtual consultant that sends automatic responses to users based on triggers, makes targeted mailings, and if integration with CRM is configured, sends customer data to it, sorting it according to the filter you set .
Advantages of chatbots for Instagram:
- instant responses to user requests 24/7, which affects their loyalty;
- increase in sales - customers do not go to competitors because of a long wait;
- reminder mailing lists that promote customer retention;
- savings on salaries of managers - you do not need a lot of employees to process orders in direct.
Chatbot makes doing business much easier. You can entrust him with all routine processes and direct the freed up resources to other areas.
What business tasks does a chatbot solve
This tool provides 24/7 support for your business. Below is a list of functions that can be assigned to a bot on Instagram.
Answers to frequently asked questions
Business accounts often receive direct messages with questions about product availability, prices and sizes, location, lead times, delivery terms, and the like. Make buttons with frequently repeated questions so that the Instagram bot instantly gives automatic answers, and managers do not have to constantly be distracted. Another option is to set up the bot to respond to a specific trigger word in the user's message.
Automation of part of the processes in the sales funnel
In the process of interaction between the chatbot and users, the needs of the latter are identified and non-targeted leads are screened out. If the sales funnel is small, the Instagram bot can act as a real “salesperson” and close the deal. Usually, to place an order, you still need the participation of a live manager - for this they add a button to switch to the operator - but the chatbot saves time significantly, due to which employees are less loaded and able to serve more customers. If three people were required to process applications, it is quite possible that after connecting the chatbot, one manager will be enough for the same amount of work. And the bot will cope with the recording for a consultation on its own.
Engage followers, increase trust
Instagram bots can be used to engage your audience. For example, make a quiz where you need to choose one of the answer options, and at the end the participant receives a lead magnet - useful material. Getting something valuable for free will affect the user's opinion of you, increase trust, and perhaps later they will want to try a paid product.
Also, through the chatbot, you can give useful information and talk about the expert, his experience, give a link to cases or portfolios. In this case, there is more chance that the user will see this information and become interested than if he has to search through the entire profile - not everyone will do this.
Targeted mailings
You can set up filters to send messages through the bot based on interests, client status and other data.
Reminders
When you're running consultations or webinars, clients may forget the start time. This problem is solved by an automated reminder sent by a chatbot to Instagram - people spend a lot of time here and are unlikely to miss the message.
Collecting feedback
Use the Instagram bot to conduct surveys and collect feedback. This is a convenient way to discover your weaknesses and problematic customers without spending a lot of effort.
Saving user data
Add a Data Entry block to your script to collect user data and then use it to personalize messages and segment audiences. The chatbot will send this data to CRM.
React to Stories tags
In order not to miss your account's Stories tags and quickly respond to them, set up a thank you message that will be sent automatically. We advise you to thank not only with words, but also with a small discount or other bonus to encourage new purchases and marks. By the way, you can run promotions yourself with gifts for tagging your stories — this is how you make the most of the word of mouth effect.
API request to receive data from external sources
You can add an "API request" block to the bot script to receive data from external systems, which will immediately be displayed in a message to the user. For example, you can report the weather by the name of the city, search by the name or article number of the product and display the result in the chatbot.
You can also place a subscription widget on the site to recruit a subscriber base from there. Optionally, you can create a widget for other channels - Facebook, WhatsApp, Telegram and VK.
For team work, you can invite several managers to your account: then each of them will have access to chats. This process is described in more detail in our instructions.
Discover a chatbot on Instagram
Convert followers into regular customers, automate communication with them and improve sales.
Create a chatbot
Examples of Instagram chatbots
Using several Instagram accounts with chatbots, I will show you how to use this tool.
First example: personal online training app account. After switching to the dialogue, buttons with the most frequent questions immediately appear in front of the user. Click the button with the question of interest, and the bot gives the answer. Given the large number of subscribers, this saves a lot of time.
Bot for Instagram sports applicationThere is a flaw here - the inability to return to the choice of the question. If the user clicked, for example, “How to sign up for a workout?”, He will not be able to ask something else - only if he deletes the correspondence and starts it again. For the convenience of bot subscribers, it is necessary to add the ability to return to the main menu.
The second example: a bot in an additional account of a millionaire blogger created to post reviews. The user writes the word “quest” in direct, which is a trigger, and an interactive game begins. After passing it, the participant receives a checklist with useful materials.
Bot-quest involving the userThe bot was created in order to interest the subscriber and motivate them to learn from the blogger. Here I do not see any shortcomings, all steps are thought out. In the final, the participant is invited to watch one of two courses to choose from, and only after clicking on the link does a message come to the chat with a checklist.
Chatbot gives a link to download a fileThird example: a bot in the account of a specialist who creates them. Several buttons with questions are given, including one can view the portfolio by clicking on the link. The disadvantage here, as in the first case, is the inability to return to the choice of the question.
Bot for selling servicesChatbots are used for engagement, informing, selling - you can find different uses, but you need to carefully consider the logic of the bot so that the user does not leave without getting an answer to the question.
How to create a chatbot for Instagram in SendPulse
How to connect and run a chatbot in SendPulse
Connecting Instagram
To connect a bot to Instagram, you must have a Facebook business page and an Instagram business account .
Instagram must be allowed to access messages, and Facebook must be allowed to access messages from Instagram in the Inbox. The connection process is described in detail in our knowledge base. After connecting, you will have the bot settings in your SendPulse account. More on this later.
Interface
Here is your SendPulse personal account, Chatbots section, where you will create chatbots. In the "Bot Structure" tab, you build its logic.
Personal account where you create and manage an Instagram botIn the "Audience" tab, you can see everyone who subscribed to the bot: their status, last activity time, tags, chats with them.
The "Statistics" tab shows the number of subscribers for the period, the number of sent and incoming messages, the number of sessions.
It is also possible to set up auto-posting.
Statistics on bot messages in the SendPulse personal accountLaunching auto-replies and chat bot message threads
When creating chat bots, a trigger element is used - this is an event that triggers auto-replies and message threads. There are two types of triggers in the SendPulse chatbot builder: pre-installed and manually created.
Connected by default:
- welcome series - sent after subscription;
- standard response - the bot will send it in response to any message for which the command is not registered;
- message after unsubscribing.
Each of them can be edited for yourself.
Trigger "Welcome series"
Select the greeting series, click "Edit chain" and go to the editor.
Setting up a greeting seriesAs we saw in the examples section, the greeting message is often not used. However, it makes the chatbot understandable to the subscriber. You can disable this trigger, but we recommend that you leave it on and continue the welcome series by attaching new messages and other blocks. It is desirable to give the bot a "human" face, to come up with an assistant character.
It is also recommended here to tell you how to unsubscribe from the bot. The standard commands for this action are "/unsubscribe" and "/stop". You can edit or delete this text block.
"Standard response" trigger
It is unrealistic to prescribe chains for all user requests. If the bot does not recognize the user's phrase, it will receive a standard response. It should be a universal message for solving different issues.
You can redirect the client to a chat with the manager. To do this, our chatbot has an "Action" block. Select the "Open Chat" option when building a thread. Communication will continue smoothly, without notifying the user that the chat has been switched to the manager.
Write in the structure of the bot switching to an employeeTrigger "Unsubscribe from the bot"
If the user enters the unsubscribe command, he will receive a notification that he has successfully unsubscribed. Don't forget to remind him that he can subscribe again by typing "/start" or "/subscribe" - make this message as warm as possible. Continue the line with the personification of the bot in the form of a character, if one already exists.
Creating your own trigger
If you want to create a new trigger, click on the appropriate button in the Bot Structure section.
Adding a trigger in the Instagram chatbot builder in SendPulseThere are three types of triggers. You can select "After Subscription" and simply specify the time after which the message will be sent. The "Command" type starts the chain when it receives messages from the subscriber with the words that you specify as keywords. Using the "A360 Event", you can send a message to the user in the messenger with a confirmation of the reservation or with information about his order. Read more about this in the knowledge base.
All the features of the SendPulse chatbot builder
To build a chain in the visual editor, seven blocks are available on the left panel: "Message", "Chain", "Action", "Filter", "API Request", "Pause" and "Random".
Blocks in the thread editorMessage block
You can add the following elements to a chatbot message in SendPulse:
- text;
- emoji;
- picture;
- button with or without link;
- card;
- variables;
- user input;
- quick answers.
Write your message in the text box. You can insert emojis and variables to personalize information. To do this, click on the {} sign in the upper right corner of the field and select the desired variable from the drop-down list. Each user will receive a message with the value of the variable from their contact.
Add variables for personalizationButton is one of the main elements of user communication with the chatbot. Thanks to her, the subscriber sets the direction for the further development of the bot script.
What types of buttons can be added:
- "Continue the chain" - connects the "Message" element with other elements;
- "Link" - sends to the specified address, for example, to an online store;
- "Payment" - allows you to accept payments in the chatbot.
Up to three buttons can be added to one block. There is a 20 character limit for text on it.
In the SendPulse constructor, it is possible to add a payment buttonIf you wish, you can diversify the message with visual content by adding pictures or cards in the form of a carousel to it. Cards are very convenient for showcasing products, because you can also add a title and a button with a link to an external source or payment form.
Place cards in a carousel inside blockOf particular interest is the ability to enter user data . You can collect subscriber responses and store them in a variable for later use.
Add a data entry element to validate and save subscribers' answersRead more: "How to set up manual input of user variables"
You can also create quick response buttons under the message - so that the user does not enter values, but chooses from the proposed ones. Up to ten quick response buttons are available. For example, you can create multiple quick responses for age, clothing size, city, and so on.
Use quick replies for user convenienceContinuation of the chain
You can connect the "Message" block with other elements using the button or the "Data entry" function. Then the next message will be sent after the user's action. But you can continue the chain without waiting for it. In this case, we recommend adding a "Pause" block to check if the subscriber interacted with the chain and send a message after a certain time.
Read more: "How to continue the chatbot thread without user action"
"Action" block
From the panel on the left, drag this element onto the workspace. Select the desired action.
Check the appropriate actionWhat the “Action” block allows you to do:
- Open a chat — like when a client needs a personal consultation or a manager needs to complete a transaction. After that, a private chat with the page administrator will open. You can set up notifications for the manager via the email used to register with SendPulse, or via web push to the browser.
- Unsubscribe from the bot - when you need to remove a person from the list of subscribers and no longer send him messages.
- Add tag - to segment the audience when sending mailing lists - then the messages will be more targeted. For example, tag subscriber preferences or some characteristics. Read more - "How to assign tags to chatbot subscribers".
- Delete tag - the tag can be removed if it has become irrelevant for the subscriber.
- Set variable - set the value of the variable to use the data in the future. This can be order information or personal data that you use to filter the audience for mailings. Saved variables are available in the "Audience" tab in your account.
- Send webhook - configure sending data about the event in the bot chain to your system for further work with this client. Learn more — How to set up webhook sending in chatbots.
- Create deal — you can set up chatbot integration with your CRM.
Filter block
Allows you to segment subscribers by their personal data and previous messages, as well as create quizzes. You can filter by variable value, presence of a tag, participation in a chain, and receipt of a newsletter.
Filtering by variable value using additional conditionsRead more:
- “How to use the “Filter” element in the chain constructor”
- "Case: Creating quiz chatbots: the correct mechanics of calculating results"
- "Webinar: How to make a quiz in a chatbot"
API Request block
To send a request to a third-party server to create objects or get data that can then be sent in a bot message. This functionality allows, for example: to show the weather in the specified city on request, to find and display information by product name or article in the chatbot, to create an order or register a subscriber to an event based on its data.
Get information from external sources using the API Request blockRead more: How to send and receive data from external sources
Pause block minutes to 24 hours. You can also pause until a specific date. This allows you to warm up the client, for example, before offering a purchase.
Use the "Pause" block for time intervals between messagesSelect a condition: continue the chain when the user is inactive or always. In the second case, even when switching to another script branch, messages will arrive at the specified time.
Random Block
Suitable for sending randomly selected messages with useful information: tips, interesting facts, planned exercises. With it, you can arrange tournaments and quizzes.
Random selection is also used in marketing research by A/B testing. Analyze test results and improve your chatbot.
Use the "Random" block to send random itemsRead more: "How to use the "Random" element"
More Chatbot Features in SendPulse
There are some more useful features of the Chatbot for Instagram that you you might want to use.
Bot message segmentation
You can send email campaigns to specific audience categories based on subscriber data. Due to its personalization, such a mailing will bring a greater response
Segment mailings to make them more relevant to recipientsYou can segment by "Subscription date" - to do this, select a period of time - or by conditions. There are four types of conditions: "Variable value", "Tags", "Participation in the chain", "Received the mailing list".
Subscription widget
To collect bot subscribers, place a subscription widget on the website. Connect widgets for all social networks and messengers to get the best result. Subscription widgets in SendPulse are multi-channel.
Create a Bot Subscribe WidgetLive Chat
SendPulse's chatbot service allows you to manage chats with your chatbot subscribers in all messengers, including Instagram, through a common unified chat. This is convenient if customers come from different channels.
Correspondence with clients in all messengers in a single live chatSimple but powerful landing page builder
Create a mobile landing page, online store or multilink for Instagram and promote it through chat bots in messengers, email and SMS - all on one platform!
Create a landing page
An example of building an Instagram chatbot in SendPulse
Now I’ll show you how to create an Instagram chatbot using a simple bot for a skincare store as an example: in the SendPulse editor looks like this:
Bot scheme in the visual editorLet's take a step-by-step look at what needs to be done to build such a chain in SendPulse. For simplicity, I will not build it from scratch, but will edit the welcome series. In the process, we will also create new chains.
Setting up the start block
In the text field of the "Message" block, enter a greeting.
We write a greeting messageI click "Add", I select the element "Picture". I'm uploading an image.
Adding a picture to the bot's messageNext, I add a new text field to the block and fill it in. I click "Add button". I need three buttons: "I want to place an order", "I need a consultation" and "I want to attend a master class".
Adding buttonsCreating the following messages
Drag the "Message" blocks from the panel on the left - three times, for each of the answer options. We add the elements necessary for the logic of the bot.
Moving new blocks of messages to the working areaI want to place a button in the block that leads to the site. To do this, under the text of the button, I mark "Link" and enter the site address. In the visual editor, the presence of a link is displayed as chain links.
Inserting a linkClicking on the button will take the user to the site.
Also in each of the blocks I create another button with the inscription "Back to questions" - it is necessary to give users this opportunity.
To do this, you need to create a new chain. I return to the "Bot Structure" section, select "Saved", click "Create a chain".
Create a new threadThe "Back to questions" button should lead to a block where there are two other options - in addition to the one that the user has selected. For example, first he clicked "I want to place an order." Then he returned to the questions and chose the option with a master class. Then I pressed “Back” again and asked for a consultation. Then his path will look like this:
It is necessary to take into account all options for user actionsSave the chain. I create a chain for each button from the welcome message. Back to the hello series.
From the left pane, I drag the Thread element into the workspace, which will launch another series of messages, one of the ones we just made. I open the block and select the chain I need.
Selecting the chain to runConnecting to the previous message. I repeat the steps for the remaining blocks.
At the stage where the user asks for a consultation, you need to open the chat, as shown above.