• Carlos Loyo

Creando Bot en Instagram con Python y Selenium

Hola amigos blogueros,


Uno de mis alumnos en la Universidad "Mateo Laborde" genero dos códigos que permiten la creación de cuentas en instagram y análisis de Like, las cuales comparto:


Creador de cuenta y realización de like;

#Instagram account bot creator by Mateo --> Bot para crear cuentas de Ig y likear fotos de ciertas cuentas para tener comportamiento (Normal) - Las cuentas generadas se van guardando en un txtfrom selenium import webdriver
from time import sleepclass InstaBot:
    def start(self,email, fullname, username, password):
        f = open('accounts', 'a')
        self.driver = webdriver.Chrome()
        self.driver.get('https://www.instagram.com/accounts/emailsignup/')
        self.username = username
        self.password = password
        sleep(3)
        s=str(email+"\n"+username+"\n"+password+"\n")
        f.write(s)
        f.close()
        #email
        self.driver.find_element_by_name("emailOrPhone")\
            .send_keys(email)
        #fullname
        self.driver.find_element_by_name("fullName")\
            .send_keys(fullname)
        #username
        self.driver.find_element_by_name("username")\
            .send_keys(username)
        #password
        self.driver.find_element_by_name("password")\
            .send_keys(password)
        sleep(3)
        self.driver.find_element_by_xpath("//button[contains(text(), 'Sign up')]")\
            .click()
        sleep(2)
        #notNow
        self.driver.find_element_by_xpath("//button[contains(text(), 'Not Now')]")\
            .click()
        #search
    def search(self,searchaccount):        self.driver.find_element_by_xpath('//*[@id="react-root"]/section/nav/div[2]/div/div/div[2]/input')\
            .send_keys(searchaccount)
        sleep(2)
        #firstsearchresult
        self.driver.find_element_by_xpath('//*[@id="react-root"]/section/nav/div[2]/div/div/div[2]/div[2]/div[2]/div/a[1]/div/div[2]/div/span')\
            .click()
        sleep(2)
    def follow(self):
        self.driver.find_element_by_xpath("//button[contains(text(), 'Follow')]")\
            .click()    def likepic(self,amount):
        #likepic
        self.driver.find_element_by_class_name('v1Nh3')\
            .click()
        i = 1
        while i <= amount:
            sleep(1)
            self.driver.find_element_by_class_name('fr66n')\
            .click()
            self.driver.find_element_by_class_name('coreSpriteRightPaginationArrow')\
            .click()
            i += 1
        self.driver.get('https://www.instagram.com')
    def exit(self):
        self.driver.quit()mybot = InstaBot()
cont = 1
email = "itsbarbamilllermiller12"
fullname = "BarbaMiller"
username = "itsbarbamilllermiller12"
password = "InstaXXXXX"
while cont < 5:
    email = email+str(cont)+"@hotmail.com"
    fullname = fullname+str(cont)
    username = username+str(cont)
    mybot.start(email,fullname,username, password)
    mybot.search('nike')
    mybot.follow()
    mybot.search('adidas')
    mybot.search
    mybot.exit()
    email = "itsbarbamilllermillerfd"
    fullname = "BarbaMillers"
    username = "itsbarbamilllermillersd"
    cont += 1

Analizador de like;

#Instagram like pic from 1 account by Mateo Laborde --> hay que completar los las dos variables abajo con la cuenta de la cual van a salir los likes, 
from selenium import webdriver
from time import sleepclass InstaBot:
    def start(self, username, password):
        self.driver = webdriver.Chrome()
        self.driver.get('https://www.instagram.com')
        self.username = username
        self.password = password
        sleep(2)
        #user
        self.driver.find_element_by_xpath('//*[@id="react-root"]/section/main/article/div[2]/div[1]/div/form/div[2]/div/label/input')\
            .send_keys(username)
        #pass
        self.driver.find_element_by_xpath('//*[@id="react-root"]/section/main/article/div[2]/div[1]/div/form/div[3]/div/label/input')\
            .send_keys(password)
        #enter
        self.driver.find_element_by_xpath('//*[@id="react-root"]/section/main/article/div[2]/div[1]/div/form/div[4]/button/div')\
            .click()
        sleep(3)
        #notNow
        self.driver.find_element_by_xpath("//button[contains(text(), 'Not Now')]")\
            .click()
        sleep(2)
        #search
    def search(self,searchaccount):
        self.driver.find_element_by_xpath('//*[@id="react-root"]/section/nav/div[2]/div/div/div[2]/input')\
            .send_keys(searchaccount)
        sleep(3)
        #firstsearchresult
        self.driver.find_element_by_xpath('//*[@id="react-root"]/section/nav/div[2]/div/div/div[2]/div[2]/div[2]/div/a[1]/div/div[2]/div/span')\
            .click()
        sleep(3)    def likepic(self,amount):
        #likepic
        self.driver.find_element_by_class_name('v1Nh3')\
            .click()
        i = 1
        while i <= amount:
            sleep(2)
            self.driver.find_element_by_class_name('fr66n')\
            .click()
            self.driver.find_element_by_class_name('coreSpriteRightPaginationArrow')\
            .click()
            i += 1
        self.driver.get('https://www.instagram.com')
    def exit(self):
        self.driver.quit()mybot = InstaBot()
searchaccount = input("Enter Account to search: ")
amount = input("Enter Amount of likes: ")
mybot.start('usernamededondesalenlikes','passworddedondesalenlikes')
mybot.search(searchaccount)
mybot.likepic(int(amount))
mybot.exit()

Nos vemos en el próximo capitulo,

Hasta pronto!!!