-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathinstagramBot.py
85 lines (74 loc) · 3.85 KB
/
instagramBot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#----------------------------
# |
# Instagram Bot - RaduLepy |
#https://github.com/Radulepy/InstagramBot
# UPDATE: 21.01.2022 |
#----------------------------
from selenium import webdriver
from time import sleep
from selenium.webdriver.common.keys import Keys
import random
import string
#Change this list to your wanted comments
comments = [' I am a robotttt', 'Nice ', 'loool very nice! ', 'I like it!', 'Super ;) ', 'hmmm, interesting ', ' hi', 'I am a sheep ', 'learn something new ', 'Mind blowing ', 'I like to eat wires', ]
#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"C:\Users\Lepy\Desktop\python\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):
post = browser.find_element_by_xpath('/html/body/div[1]/section/main/div/div[1]/div/div['+str(y)+']/div['+str(x)+']')
browser.implicitly_wait(1)
post.click()
sleep(2)
postLike = browser.find_element_by_xpath('/html/body/div[6]/div[3]/div/article/div/div[2]/div/div/div[2]/section[1]/span[1]/button').click()
#postLike.click()
sleep(2)
#comment = browser.find_element_by_xpath('/html/body/div[4]/div[2]/div/article/div[3]/section[3]/div/form').click()
print("click1")
sleep(3)
comment = browser.find_element_by_xpath('/html/body/div[6]/div[3]/div/article/div/div[2]/div/div/div[2]/section[3]/div/form/textarea').click()
print("click2")
comment = browser.find_element_by_xpath('/html/body/div[6]/div[3]/div/article/div/div[2]/div/div/div[2]/section[3]/div/form/textarea').send_keys(random.choice(comments))
print("send1")
sleep(3)
sendComment = browser.find_element_by_xpath('/html/body/div[6]/div[3]/div/article/div/div[2]/div/div/div[2]/section[3]/div/form/button[2]')
sendComment.click()
print("click3")
sleep(4)
posts+=1
closePost=browser.find_element_by_xpath('/html/body/div[6]/div[1]/button')
closePost.click()
sleep(3)
print ('Nr. of posts: ' +str(posts))
sleep(5)
browser.get('https://www.instagram.com/explore/')
sleep(6)
likeAndComm()
def start():
acceptCookies = browser.find_element_by_xpath('/html/body/div[4]/div/div/button[1]');
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('YourInstagramUsername') # <- INSERT YOUR INSTAGRAM USERNAME HERE -------------------------------------------------------------------------------------------------------------------------
password = browser.find_element_by_name('password')
password.send_keys('YourInstagramPassword') # <- 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()
#browser.quit()
sleep(4)
notification = browser.find_element_by_xpath("//button[contains(text(), 'Not Now')]")
notification.click()
browser.get('https://www.instagram.com/explore/')
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()