Python programming blog

Saturday, June 5, 2021

Instagram Automation ( send messages ) using python

 Hello python programmers, In this video we're going to see about how to create a Instagram Bot using python

With the help of selenium we're going to create this one.



STEP1: Libraries Installation:

*pip install selenium 

STEP2: Importing the Libraries:

from selenium import webdriver
import time
browser = webdriver.Chrome('chromedriver.exe')
browser.get('https://instagram.com/')
time.sleep(4) 

STEP3: Login autoamation:

def login()
    Username=browser.find_element_by_xpath("/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div/div[1]/div/label/input")
    Username.send_keys("username")
    time.sleep(4)
    password=browser.find_element_by_xpath("/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div/div[2]/div/label/input")
    password.send_keys("password")
    password.submit()
    time.sleep(7)

STEP4:Blocking the Notifications

def notification():
    Notnow=browser.find_element_by_xpath('/html/body/div[1]/section/main/div/div/div/div/button').click()
    time.sleep(3)
    noti=browser.find_element_by_xpath('/html/body/div[4]/div/div/div/div[3]/button[2]').click()
    time.sleep(7)

STEP5:Message icon:

def message():
    msgclick=browser.find_element_by_class_name('xWeGp')
    msgclick.click()
    time.sleep(6)

STEP6: Final part:

def final():
    chaticon=browser.find_element_by_class_name('QBdPU').click()
    time.sleep(7)
    typename=browser.find_element_by_xpath('/html/body/div[5]/div/div/div[2]/div[1]/div/div[2]/input')
    typename.send_keys('username who you want to send.!')
    time.sleep(7)
    name=browser.find_element_by_xpath('/html/body/div[5]/div/div/div[2]/div[2]/div[2]/div/div[2]/div[2]/div').click()
    time.sleep(7)
    next=browser.find_element_by_class_name('rIacr').click()
    time.sleep(7)
    mbox=browser.find_element_by_tag_name('textarea')
    mbox.send_keys('Hi')
    send=browser.find_element_by_xpath('/html/body/div[1]/section/div/div[2]/div/div/div[2]/div[2]/div/div[2]/div/div/div[3]/button')
    send.click()


Thanks for reading this article..!

Fullcode: Github








No comments:

Post a Comment