Selenium Instagram Bot Follower

  python, selenium

I want to open an Instagram account, tap on their follower and follow all their followers. So I’ve written a selenium program. This code opens profile, then login with my username and password then tap on the followers, But after that, it doesn’t follow all the followers. Please help.

from selenium import webdriver
class InstaBot:
   

    def __init__(self):
           self.driver = webdriver.Firefox()
           self.driver.implicitly_wait(10)
           self.driver.get("https://www.instagram.com/randomusername/")
       
   def get_follower(self, username, pw):
       self.driver.find_element_by_xpath("/html/body/div[1]/section/main/div/header/section/ul/li[3]/a")
           .click()
      
      
       self.driver.find_element_by_xpath("//input[@name="username"]")
           .send_keys(username)
      
       self.driver.find_element_by_xpath("//input[@name="password"]")
           .send_keys(pw)
 
       self.driver.find_element_by_xpath('//button[@type="submit"]')
           .click()
 
       self.driver.find_element_by_xpath("/html/body/div[1]/section/main/div/div/div/section/div/button")
           .click()
 
       self.driver.find_element_by_xpath("/html/body/div[1]/section/main/div/header/section/ul/li[2]/a")
           .click()

       
       follow = self.driver.find_elements_by_xpath("/html/body/div[5]/div/div/div[2]/ul/div/li[3]/div/div[2]")

       i =1

       for follower in follow:
            if(i !=1):
                self.driver.find_elements_by_xpath("/html/body/div[5]/div/div/div[2]/ul/div/li[1]/div/div[3]")
                    .click()

                i += 1   
      


       
 
 
my_bot = InstaBot()
my_bot.get_follower('username', 'pw')

Source: Python Questions

LEAVE A COMMENT