-
Notifications
You must be signed in to change notification settings - Fork 2
/
InstagramBot.py
307 lines (283 loc) · 18.3 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
from selenium.webdriver.common.keys import Keys
from InstagramBotUser import username, password
from colorama import Fore, Back
from selenium import webdriver
import colorama
import selenium
import wget
import time
import os
class Instagram():
def __init__(self,username,password):
self.browserProfile = webdriver.FirefoxOptions()
self.browser = webdriver.Firefox()
self.username = username
self.password = password
#self.browser.set_window_position(700, -300)
#self.browser.set_window_size(500,600)
def signIn(self):
self.browser.get("https://www.instagram.com/accounts/login/?next=%2Faccount%2Flogin&source=desktop_nav")
time.sleep(3)
usernameInput = self.browser.find_element_by_xpath("/html/body/div[1]/section/main/div/div/div[1]/div/form/div/div[1]/div/label/input")
passwordInput = self.browser.find_element_by_xpath("/html/body/div[1]/section/main/div/div/div[1]/div/form/div/div[2]/div/label/input")
usernameInput.send_keys(self.username)
passwordInput.send_keys(self.password)
passwordInput.send_keys(Keys.ENTER)
time.sleep(3)
def getFollowers(self):
self.browser.get(f"https://www.instagram.com/{self.username}")
time.sleep(3)
followersButton = self.browser.find_element_by_xpath("/html/body/div[1]/section/main/div/header/section/ul/li[2]")
followersButton.click()
time.sleep(3)
dialog = self.browser.find_element_by_css_selector("div[role=dialog] ul")
followersCount = len(dialog.find_elements_by_css_selector("li"))
print(f"first count: {followersCount}")
action = webdriver.ActionChains(self.browser)
while True:
dialog.click()
action.key_down(Keys.SPACE).key_up(Keys.SPACE).perform()
time.sleep(3)
newCount = len(dialog.find_elements_by_css_selector("li"))
if followersCount != newCount:
followersCount = newCount
print(Fore.GREEN)
print(f"updated count: {newCount}")
time.sleep(2)
else:
break
followers = dialog.find_elements_by_css_selector("li")
followersList = []
for user in followers:
link = user.find_element_by_css_selector("a").get_attribute("href")
print(Fore.RED)
print(f"User profile: {link}")
followersList.append(link)
try:
with open("Wordlist/followers.txt","a",encoding="utf-8") as file:
for item in followersList:
file.write(item + "\n")
file.close()
except:
file.close()
print(Fore.BLUE)
print(f"\nall users profile save >> /Wordlist/followers.txt")
def followUser(self,username):
self.browser.get("https://www.instagram.com/"+username)
time.sleep(3)
followButton = self.browser.find_element_by_tag_name("button")
#followButton = self.browser.find_element_by_xpath("/html/body/div[1]/section/main/div/header/section/div[1]/div[1]/div/div[2]/div/span/span[1]/button")
#print(followButton.text)
if followButton.text != "Takiptesin" or followButton.text != "Message" or followButton.text != "Following" or followButton.text != "Mesaj" or followButton.text == "Follow Back":
followButton.click()
print(Fore.GREEN)
print("following is succesfull")
time.sleep(2)
else:
print(Fore.RED)
print("Already following")
def unFollowUser(self,username):
self.browser.get("https://www.instagram.com/"+username)
time.sleep(3)
#followButton = self.browser.find_element_by_tag_name("button")
followButton = self.browser.find_element_by_xpath("/html/body/div[1]/section/main/div/header/section/div[1]/div[1]/div/div[2]/div/span/span[1]/button")
if followButton.text != "Follow Back" or followButton.text == "Takiptesin" or followButton.text == "Message" or followButton.text == "Following" or followButton.text == "Mesaj":
followButton.click()
confirmButton = self.browser.find_element_by_xpath("/html/body/div[6]/div/div/div/div[3]/button[1]")
confirmButton.click()
print(Fore.GREEN)
print("unfollowing is succesfull")
time.sleep(2)
else:
print(Fore.RED)
print("Already unfollowing")
def InstallBrowser():
try:
print(Fore.GREEN)
url = 'https://github.com/mozilla/geckodriver/releases/download/v0.28.0/geckodriver-v0.28.0-linux64.tar.gz'
filename = wget.download(url)
print("\n\n")
os.system("tar -xvf geckodriver-v0.28.0-linux64.tar.gz")
os.remove("geckodriver-v0.28.0-linux64.tar.gz")
os.system("mv geckodriver /usr/bin")
os.system("chmod 777 /usr/bin/geckodriver")
os.remove("geckodriver")
except KeyboardInterrupt:
print(Fore.RED)
print("\nBye bye")
def fileConts():
haveOrnotFile = os.path.exists("/usr/bin/geckodriver")
if haveOrnotFile != True:
print(Fore.BLUE)
print("""
.
...'',,. .''''.....
.'''''''''.... .'''. .......''.....
..''.','...''.... '. ... .''. .:ddl. .................
..','',,''...''''...''',,. ,od:..:dd:..;dd; .:cccc:,. ..'......'''......
...'','..''.....'... ..',,''::. ;ddc. ;dd:..'od;.,odc''::c;..,:;'...........,'..'.....
...'''..''..''.........';'':;::';o, .coo:;cdl. 'od,.'lo:.......,:lcclc'........,'..'.........
...'...............,cooolc,..lc.:d;.cl...;c;,'',....;l,...,c:::;..lxo::lod;..,;....'...............
....''...........;lol,.;odo' 'c:,,,,;c,........ ..................,::::loc'.cddl:,'.....'...........
.......'.........:dl'. ;dd; .',''.,c,.... .;:;'.,:. .....'.... ..;;..cddl;,col,....''......'....
...........'.'.... 'ddo:....ldo; ''',.. ;olcooc;. .... 'dd:. .,ldo....','.....'...'..
.................'. ,ooollol:'.. .co:;ll;,. . .''. .cddl. ..........'..'''....
.............''. ... ....';. ,llolcc:' .cdc'. .. .........'.......
.. .. ...... ...'::. .. ................
...... . .;:cldc,. ......
......... .lxoccl, .''......
....... .,;:coo:. .',...'.
....... .;;. ........
..'... .. .'. ....'.
..... .;. ;;'. ...''.
..... .;, .;... ....'.
.... .,;;;;,,. .....
... ...,;' ....
..,;cll:.
.cdocll,
.,clcloc,.
...;cc.
.,'. .,:'
.;ol;;cl;. Oğulcan KAÇAR
.;oddl;'. github.com/OgulcanKacarr
.:lloolc:'.
.....'...'.......''..'.. .''. ...... ..'....'...'.......'.........
.........
..........
..........
.''....'..
""")
print(Fore.GREEN)
print("\n\n[!] please wait, files are uploading..\n")
print("============================================")
time.sleep(3)
try:
InstallBrowser()
print(Fore.BLUE)
print("Download complete")
print(Fore.RED)
except KeyboardInterrupt:
print(Fore.RED)
print("\nCancel")
exit()
else:
pass
colorama.init()
os.system("clear")
fileConts()
print(Fore.GREEN)
print("WELCOME".center(110,"*"))
print(Fore.BLUE)
print("""
.
...'',,. .''''.....
.'''''''''.... .'''. .......''.....
..''.','...''.... '. ... .''. .:ddl. .................
..','',,''...''''...''',,. ,od:..:dd:..;dd; .:cccc:,. ..'......'''......
...'','..''.....'... ..',,''::. ;ddc. ;dd:..'od;.,odc''::c;..,:;'...........,'..'.....
...'''..''..''.........';'':;::';o, .coo:;cdl. 'od,.'lo:.......,:lcclc'........,'..'.........
...'...............,cooolc,..lc.:d;.cl...;c;,'',....;l,...,c:::;..lxo::lod;..,;....'...............
....''...........;lol,.;odo' 'c:,,,,;c,........ ..................,::::loc'.cddl:,'.....'...........
.......'.........:dl'. ;dd; .',''.,c,.... .;:;'.,:. .....'.... ..;;..cddl;,col,....''......'....
...........'.'.... 'ddo:....ldo; ''',.. ;olcooc;. .... 'dd:. .,ldo....','.....'...'..
.................'. ,ooollol:'.. .co:;ll;,. . .''. .cddl. ..........'..'''....
.............''. ... ....';. ,llolcc:' .cdc'. .. .........'.......
.. .. ...... ...'::. .. ................
...... . .;:cldc,. ......
......... .lxoccl, .''......
....... .,;:coo:. .',...'.
....... .;;. ........
..'... .. .'. ....'.
..... .;. ;;'. ...''.
..... .;, .;... ....'.
.... .,;;;;,,. .....
... ...,;' ....
..,;cll:.
.cdocll,
.,clcloc,.
...;cc.
.,'. .,:'
.;ol;;cl;. Oğulcan KAÇAR
.;oddl;'. github.com/OgulcanKacarr
.:lloolc:'.
.....'...'.......''..'.. .''. ...... ..'....'...'.......'.........
.........
..........
..........
.''....'..
""")
print(Fore.RED)
print(f"\n1- Attract Followers\n2- Auto Follower\n3- Automatic Unfollow\n4- Help\n5- Exit")
while True:
try:
print(Fore.GREEN)
choose = int(input("Please enter a option: "))
print(Fore.RED)
if choose == 1:
#getYourFollowers
instagram = Instagram(username,password)
instagram.signIn()
instagram.getFollowers()
elif choose == 2:
print(Fore.BLUE)
a = int(input("Use single=1 / Use list=2:"))
if a == 1:
# auto following / unfollowing
print(Fore.GREEN)
user = input("Person to follow: ")
instagram = Instagram(username,password)
instagram.signIn()
instagram.followUser(user)
else:
userList = []
users = open("Wordlist/userList.txt","r",encoding="utf-8")
for line in users:
print(f"following users: {line}")
userList.append(line)
for user in userList:
instagram = Instagram(username,password)
instagram.signIn()
instagram.followUser(user)
time.sleep(2)
elif choose == 3:
a = int(input("Use single=1 / Use list=2:"))
if a == 1:
# auto following / unfollowing
print(Fore.GREEN)
user = input("Person to unfollow: ")
instagram = Instagram(username,password)
instagram.signIn()
instagram.unFollowUser(user)
else:
userList = []
users = open("Wordlist/UnUserList.txt","r",encoding="utf-8")
for line in users:
print(f"Unfollowing users: {line}")
userList.append(line)
for user in userList:
instagram = Instagram(username,password)
instagram.signIn()
instagram.unFollowUser(user)
time.sleep(2)
elif choose == 4:
print(Fore.BLUE)
print("HELPING".center(100,"*"))
print(Fore.YELLOW)
print("""
[Attract Followers] : here you can save all the followers in a text file.
[Auto Follower] : Here you can automatically follow one or more users that you pull from a text file.
[Automatic Unfollow]: Here you can automatically unfollow one or more users that you pull from a text file.
""")
elif choose == 5:
print(Fore.GREEN)
print("bye bye")
break
except Exception as e:
print(Fore.RED)
print(f"Error code: {e}")
print(Fore.BLUE)
print("There may be a problem with Instagram. Please try again later. :(")
except KeyboardInterrupt:
print(Fore.GREEN)
print("bye bye")
exit()