Uploaded by Danny Boy

codeupdated

advertisement
#----------------------------
#|
# Instagram Bot - RaduLepy|
#https://github.com/Radulepy/InstagramBot
# UPDATE: 17.04.2021|
#----------------------------
from selenium import webdriver
from time import sleep
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.wait import WebDriverWait
import random
import string
#Change this list to your wanted comments
comments = ['test ', 'test3', 'test4 ', 'test645 ', ' test56', 'I am a sheep ', 'the most underrated and active meme page is @tweaking.memorial ', 'ok ', 'testend', ]
#This are some variables to keep tracking of the posts
posts=0
#Chromedriver path. Make sure to have the same Chromedriver version as your Google Chrome browser
browser = webdriver.Chrome(executable_path= r"./chromedriver.exe") # <----- ENTER PATH HERE
browser.get(('https://www.instagram.com/accounts/login/?source=auth_switcher'))
sleep(2)
def likeAndComm(): # Likes and Comments the first 9 posts
global posts
for y in range (1,4):
for x in range(1,4):
sleep(2)
postLike = browser.find_element_by_xpath('/html/body/div[1]/section/main/section/div/div[2]/div/article[1]/div/div[3]/div/div/section[1]/span[1]/button').click()
#postLike.click()
sleep(2)
#comment = browser.find_element_by_xpath('/html/body/div[1]/section/main/section/div/div[2]/div/article[1]/div/div[3]/div/div/section[3]/div/form/textarea').click()
print("click1")
sleep(3)
comment = browser.find_element_by_xpath('/html/body/div[1]/section/main/section/div/div[2]/div/article[1]/div/div[3]/div/div/section[3]/div/form/textarea').click()
print("click2")
comment = browser.find_element_by_xpath('/html/body/div[1]/section/main/section/div/div[2]/div/article[1]/div/div[3]/div/div/section[3]/div/form/textarea').send_keys(random.choice(comments))
print("send1")
sleep(3)
sendComment = browser.find_element_by_xpath('/html/body/div[1]/section/main/section/div/div[2]/div/article[1]/div/div[3]/div/div/section[3]/div/form/button[2]')
sendComment.click()
print("click3")
sleep(4)
posts+=1
sleep(3)
print ('Nr. of posts: ' +str(posts))
sleep(5)
browser.get('https://www.instagram.com')
sleep(6)
likeAndComm()
def start():
acceptCookies = browser.find_element_by_xpath('/html/body/div[1]/section/main/div/div/div[1]/div/form/div/div[1]/div/label/input');
acceptCookies.click();
sleep(4);
#browser.implicitly_wait(3) #this is another wait function.If you would like to run the script faster, change all sleep() to this
username = browser.find_element_by_name('username')
username.send_keys('USERNAME') # <- INSERT YOUR INSTAGRAM USERNAME HERE -------------------------------------------------------------------------------------------------------------------------
password = browser.find_element_by_name('password')
password.send_keys('PASSWORD') # <- INSERT YOUR INSTAGRAM PASSWORD HERE -----------------------------------------------------------------------------------------------------------------------
nextButton = browser.find_element_by_xpath('/html/body/div[1]/section/main/div/div/div[1]/div/form/div/div[3]/button')
nextButton.click()
sleep(4);
noSave = browser.find_element_by_xpath('/html/body/div[1]/section/main/div/div/div/div/button')
noSave.click()
#browser.quit()
sleep(4)
notification = browser.find_element_by_xpath("/html/body/div[5]/div/div/div/div[3]/button[2]")
notification.click()
browser.get('https://www.instagram.com')
sleep(6)
likeAndComm() # likeAndComm function ----------------------------------------------------------------------------------------------------------------------------------------------------------
#post = browser.find_element_by_xpath('//*[@id="react-root"]/section/main/div/article/div[1]/div/div[1]/div[2]')
#post.click()
sleep(5)
#Start the programm
start()
Download