Automated Instagram Message Sending Using Python With Source Code
Introduction :
Everyone is using Instagram nowadays . But we might have gotten tired of liking , commenting and following every now and then . So why not automated this process . So now we make a automation tool by using python . By using This tool , we can save a lot of time and move helpful for business pages as it grows your audience , increase your reach and generate more ideas . In other words automation allows you to prepare ahead of time . Automating your Instagram Messages is all about being able to formulate a strategy in advance .
Language And Interface :-
Automated Instagram Message Sending Using Python , A Versatile Programming
Language With Source Code by using selenium , A Python Library .
Required Modules Or Packages:-
You Need The Packages List Given Below :-
1. Selenium : It is an open source tool that automates web browsers .
2. Web_driver manager : It provides a way to automatically manage the drivers for different web browsers .
3. Chrome Driver : It is a separate executable that selenium web driver uses to control chrome .
4. Google Chrome : It is a search engine by Google and a type of web browser .
How To Run The Code :-
Step 1 . First , You Download and Install Visual Studio Code or VS Code In your PC or Laptop by VS Code Official Website .
Step 2 . Now Open CMD As Administrator and install the above packages using pip .
Step 3 . Now Open Visual Studio Code or Any other Code Editor .
Step 4. Now Make The file named as main.py .
Step 5 . Now Copy And Paste The Code from the Link Given Below
Step 6 . After pasting The code , Save This & Click On Run Button .
Step 7 . Now This code will takes username and password as a input of your Instagram ID .
Step 8 . Now you will see the output .
Code Explaination :-
This Python code is used to Automated message sending on Instagram .
Step-by-Step Guide Given Below:-
Imports :
• Selenium : It is an open source tool that automates web browsers .
• Web_driver manager : It provides a way to automatically manage drivers for different web browsers .
• Chrome Driver : It is a separate executable that selenium web driver uses to control chrome .
• Google Chrome : It is a search engine by Google and a type of web browser .
driver = webdriver.Chrome(ChromeDriverManager().install()) :- Using Chrome with this code is always work . Before declaring a Class we will make a list of users ( any no. of users in this code I am using three users.) in that list you have to send the username of the person you want to send a message to and the message we want to send to all the users.
Code given below :-
Audience = [ ‘sundarpichai’,’virat.kholi’,’rudymancuso’]
Message = “testing of a bot”
Here I am creating a class function all the code will be written inside this class so, In the end, we just have to just call this class. Let’s create an __init__ function that can be called when an object is created from the class,__init__ will provide the access that is required to initialize the attributes of the class.
Code given below :-
class bot:
def __init__(self, username, password, audience, message):
# initializing the username
Self.username = username
# initializing the password
Self.password = password
# passing the list of user or initializing
Self.user = user
# passing the message of user or initializing
Self.message = message
# initializing the base url.
Self.base_url = ‘https://www.instagram.com/’
# here it calls the driver to open chrome web browser.
Self.bot = driver
# initializing the login function we will create
Self.login()
Creating a Login function where all the steps will be written :-
def login(self):
Self.bot.get(self.base_url)
# ENTERING THE USERNAME FOR LOGIN INTO INSTAGRAM
Enter_username = WebDriverWait(self.bot, 20).until(
Expected_conditions.presence_of_element_located((By.NAME, ‘username’)))
Enter_username.send_keys(self.username)
# ENTERING THE PASSWORD FOR LOGIN INTO INSTAGRAM
Enter_password = WebDriverWait(self.bot, 20).until(
Expected_conditions.presence_of_element_located((By.NAME, ‘password’)))
Enter_password.send_keys(self.password)
# RETURNING THE PASSWORD and login into the account
Enter_password.send_keys(Keys.RETURN)
Time.sleep(5)
HANDLING POP-UP BOXES :– When you log in to Instagram you will come across two pop-up boxes as shown in the images. The first one will be asking about do you want to save info or not it will click on not now. The second one will be asking you to turn off the notifications or not so we will again click on not now as shown in the given code :-
# first pop-up box
Self.bot.find_element_by_xpath(
‘//*[@id=”react-root”]/section/main/div/div/div/div/button’).click()
Time.sleep(3)
# 2nd pop-up box
Self.bot.find_element_by_xpath(
‘/html/body/div[4]/div/div/div/div[3]/button[2]’).click()
Time.sleep(4)
It’s time to create a function where we will pass the username and the password of the account in which we want to login and call our class here. Code given below :-
def init():
# you can even enter your personal account.
bot(‘username’, ‘password’, user, message_)
input(“DONE”)
Calling the Function :-
# calling this function will message everyone’s
# that is on your user’s list...☺
init()
Source Code :
Here Is Your Code Link From Where You Can Access or Copy The Code :-
Output :
Find More Projects
Complain Management using Python with a Graphical User Interface (GUI) Introduction: The Complain Management using Python program designed to manage complaints effectively …
COVID 19 Hospital Management Using Python [Django Framework] Introduction: The COVID-19 Hospital Management is a Python-based application that tracks web applications for Hospitals. …
Drawing Ganesha Using Python Turtle Graphics[Drawing Ganapati Using Python] Introduction In this blog post, we will learn how to draw Lord Ganesha …
Contact Management System in Python with a Graphical User Interface (GUI) Introduction: The Contact Management System is a Python-based application designed to …
KBC Game using Python with Source Code Introduction : Welcome to this blog post on building a “Kaun Banega Crorepati” (KBC) game …
Basic Logging System in C++ With Source Code Introduction : It is one of the most important practices in software development. Logging …