Instagram Bot using Python

Soumya Gupta
2 min readJul 26, 2019

--

Easy to use Instagram bot for your social media account and business boosting on Autopilot.

So how about building your own Instagram bot in python from scratch , sounds cool, no ?

Today i’ll be sharing step by step approach towards the same using basic Python Libraries , i’ll be extending the same with analytical insights as well in the future.

#Core functions Supported

  • Multiple accounts login
  • Searching all the accounts matching with any keyword ex- “Travel”
  • Searching and opening multiple profiles
  • Follow/Unfollow multiple handles in one shot
  • Like/Unlike n number of posts of any given handle
  • Extract followers from any given account
  • Viewing stories on auto-mode and more

View it in action

First of all we’ll be importing basic python libraries along with Selenium which controls the browsers

#Importing Libraries

from selenium import webdriver
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import matplotlib.image as mpimg

We’ll follow the above steps with creating various re-usable functions

#Creating Reusable functions such as Login, folllowersCount etc

def do_Login(username,password):
driver.get(‘https://www.instagram.com/accounts/login/')
driver.find_element_by_name(“username”).send_keys(username)
driver.find_element_by_name(“password”).send_keys(password)
driver.find_element_by_xpath(“//*[text()=’Log In’]”).click()
screenCap()

Searching and opening any profile on Instagram

#Search and open any profile

def searchAndOpenProfile(profileName):
driver.find_element_by_xpath(“//*[@placeholder=’Search’]”).clear()
driver.find_element_by_xpath(“//*[@placeholder=’Search’]”).send_keys(profileName)
time.sleep(3)
screenCap()
ele=driver.find_element_by_xpath(“//*[@class=’fuqBx’]”)
results=ele.find_elements_by_tag_name(“a”)
for i in results:
if “#” not in i.text:
i.click()
print(i.text.partition(‘\n’)[0]+” Profile Opened”)
plt.show()
break;

Code is written with auto screenshot capturing mechanism for taking reference at any give point of time.

Profile View via Bot and Extracting follower names

Also complete detailed jupyter notebook is available below on my github-

GitHub Repo Link

If you like what I did, consider following me on

GitHub, Be sure to star it on GitHub :P

Thank you for reading. I’m curious about what you think so hit me with some comments.
You can also get in touch with me directly through email.

--

--