-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstagramBot.py
751 lines (695 loc) · 28.1 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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
from selenium import webdriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import TimeoutException
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import ElementClickInterceptedException
import MyLogger
import random
def read_credentials():
""""
Returns a tuple of
the username and password
"""
file = open("credentials.txt", "r")
username = file.readline()
temp = username.split(": ")
username = temp[1]
if username.endswith("\n"):
username = username.rstrip("\n")
password = file.readline()
temp = password.split(": ")
password = temp[1]
if password.endswith("\n"):
password = password.rstrip("\n")
file.close()
return username, password
def read_profiles():
"""
:return: list of usernames for the program to
use
"""
file = open("profiles.txt", "r")
users_list = []
for user in file:
users_list.append(user.strip())
return users_list
class InstagramBot:
def __init__(self, username, password):
"""
logs in to the owner's account
:param username: instagram username
:param password: instagram password
"""
self.username = username
self.password = password
self.driver = webdriver.Chrome('C:\chromedriver.exe')
self.driver.get("https://www.instagram.com/")
#self.my_logger = MyLogger.MyLogger()
def login(self):
"""
login function:
- open instagram
- accept all cookies
- enter credentials
"""
accept_cookies_wait = WebDriverWait(self.driver, 20).until(
EC.presence_of_element_located((By.XPATH, "/html/body/div[2]/div/div/div/div[2]/button[1]"))
)
accept_cookies_wait.click()
login_button = WebDriverWait(self.driver, 20).until(
EC.presence_of_element_located((By.XPATH, """//*[@id="loginForm"]/div/div[3]"""))
)
username_tab = self.driver.find_element_by_xpath("""//*[@id="loginForm"]/div/div[1]/div/label/input""")
password_tab = self.driver.find_element_by_xpath("""//*[@id="loginForm"]/div/div[2]/div/label/input""")
username_tab.send_keys(self.username)
password_tab.send_keys(self.password)
login_button.click()
login_info_button = WebDriverWait(self.driver, 20).until(
EC.presence_of_element_located((By.XPATH, """//*[@id="react-root"]/section/main/div/div/div/div/button"""))
)
login_info_button.click()
try:
notifications_button_wait = WebDriverWait(self.driver, 10).until(
EC.presence_of_element_located((By.XPATH, """/html/body/div[3]/div/div/div/div[3]/button[2]"""))
)
except TimeoutException:
notifications_button_wait = WebDriverWait(self.driver, 10).until(
EC.presence_of_element_located((By.XPATH, """/html/body/div[4]/div/div/div/div[3]/button[2]"""))
)
notifications_button_wait.click()
#/html/body/div[3]/div/div/div/div[3]/button[2]
#/html/body/div[4]/div/div/div/div[3]/button[2]
def navigate_to_home_page(self, user=None):
"""
Opens to home page,
once user is logged in
empty - owner home page
user - this user's home page
"""
if user is None:
self.driver.get("https://www.instagram.com/" + self.username + "/")
else:
self.driver.get("https://www.instagram.com/" + user + "/")
def navigate_to_explore_page(self):
self.driver.get("https://www.instagram.com")
def get_following_number(self):
"""
read number of followings when
located on any home page
:returns int value of ↑
"""
WebDriverWait(self.driver, 4).until(
EC.presence_of_element_located(
(By.XPATH, """/html/body/div[1]/section/main"""))
)
option1 = False
option2 = False
if len(self.driver.find_elements_by_xpath(
"""//*[@id="react-root"]/section/main/div/header/section/ul/li[3]/a/span""")) > 0:
option1 = True
elif len(self.driver.find_elements_by_xpath(
"""/html/body/div[1]/section/main/div/header/section/ul/li[3]/span/span""")) > 0:
option2 = True
if option1:
following_num = self.driver.find_element_by_xpath(
"""//*[@id="react-root"]/section/main/div/header/section/ul/li[3]/a/span""")
elif option2:
following_num = self.driver.find_element_by_xpath(
"""/html/body/div[1]/section/main/div/header/section/ul/li[3]/span/span""")
else:
return ""
temp = " "
temp = following_num.text
temp = temp.replace(',', '')
temp = temp.replace('.', '')
if "k" in temp:
temp[len(temp)] = ""
return int(temp)
# //*[@id="react-root"]/section/main/div/header/section/ul/li[3]/a/span
# /html/body/div[1]/section/main/div/header/section/ul/li[3]/span/span
# /html/body/div[1]/section/main/div/ul/li[3]/span/span
def get_followers_number(self):
"""
read number of followers when
located on any home page
:returns int value of ↑
"""
WebDriverWait(self.driver, 4).until(
EC.presence_of_element_located(
(By.XPATH, """/html/body/div[1]/section/main"""))
)
option1 = False
option2 = False
if len(self.driver.find_elements_by_xpath(
"""//*[@id="react-root"]/section/main/div/header/section/ul/li[2]/a/span""")) > 0:
option1 = True
elif len(self.driver.find_elements_by_xpath(
"""/html/body/div[1]/section/main/div/header/section/ul/li[2]/span/span""")) > 0:
option2 = True
if option1:
following_num = self.driver.find_element_by_xpath(
"""//*[@id="react-root"]/section/main/div/header/section/ul/li[2]/a/span""")
elif option2:
following_num = self.driver.find_element_by_xpath(
"""/html/body/div[1]/section/main/div/header/section/ul/li[2]/span/span""")
else:
return ""
temp = " "
temp = following_num.text
temp = temp.replace(',', '')
temp = temp.replace('.', '')
if "k" in temp:
temp[len(temp)] = ""
return int(temp)
def open_following_tab(self):
"""
opens the following tab when
located on any home page
"""
following_button = WebDriverWait(self.driver, 5).until(
EC.presence_of_element_located((By.XPATH, """//*[@id="react-root"]/section/main/div/header/section/ul
/li[3]/a"""))
)
following_button.click()
def open_followers_tab(self):
"""
opens the following tab when
located on any home page
"""
following_button = WebDriverWait(self.driver, 5).until(
EC.presence_of_element_located((By.XPATH, """//*[@id="react-root"]/section/main/div/header/section/ul
/li[2]/a"""))
)
following_button.click()
def get_following(self, num_to_scrape=10):
"""
:returns list of names of followings
located on any home page tab
Args:
num_to_scrape - how much usernames to read
-1 to scrape all
test1 - kato mu dadesh da scrapne vsichki raboti
ako ne se poqvqt promeni mejduvremenni raboti
test2 - kato mu dadesh da scrapne all,
se bugva ako ima promeni v procesa
"""
time.sleep(2)
if num_to_scrape == -1:
num_to_scrape = self.get_following_number()
time.sleep(1)
elif num_to_scrape <= 0:
return
self.open_following_tab()
time.sleep(2)
li = []
while len(li) < num_to_scrape:
try:
ul = self.driver.find_element_by_xpath("""/html/body/div[5]/div/div/div[2]/ul""")
except NoSuchElementException:
ul = self.driver.find_element_by_xpath("""/html/body/div[4]/div/div/div[2]/ul""")
li = ul.find_elements_by_tag_name("li")
# /html/body/div[4]/div/div/div[2]/ul - not such element exception mi hvurli
# /html/body/div[5]/div/div/div[2]/ul - sega maika mu deba
following_panel = self.driver.find_element_by_xpath("//div[@class='isgrP']")
self.driver.execute_script('arguments[0].scrollTop = arguments[0].scrollTop + arguments[0].offsetHeight;',
following_panel)
try:
ul = self.driver.find_element_by_xpath("""/html/body/div[5]/div/div/div[2]/ul""")
except NoSuchElementException:
ul = self.driver.find_element_by_xpath("""/html/body/div[4]/div/div/div[2]/ul""")
li = ul.find_elements_by_tag_name("li")
following_list_ = []
j = 1
for item in li:
if j > num_to_scrape:
break
following_list_.append(item.text.split("\n")[0])
j = j + 1
return following_list_
def getFollowers(self, num_to_scrape=10):
"""
:returns list of names of followers
located on any home page tab
Args:
num_to_scrape - how much usernames to read
-1 to scrape all
test1 - kato mu dadesh da scrapne vsichki raboti
ako ne se poqvqt promeni mejduvremenni raboti
test2 - kato mu dadesh da scrapne all,
se bugva ako ima promeni v procesa
"""
time.sleep(2)
if num_to_scrape == -1:
num_to_scrape = self.get_followers_number()
time.sleep(1)
elif num_to_scrape <= 0:
return
self.open_followers_tab()
time.sleep(2)
li = []
while len(li) < num_to_scrape:
try:
ul = self.driver.find_element_by_xpath("""/html/body/div[5]/div/div/div[2]/ul""")
except NoSuchElementException:
ul = self.driver.find_element_by_xpath("""/html/body/div[4]/div/div/div[2]/ul""")
li = ul.find_elements_by_tag_name("li")
# /html/body/div[4]/div/div/div[2]/ul - not such element exception mi hvurli
# /html/body/div[5]/div/div/div[2]/ul - sega maika mu deba
following_panel = self.driver.find_element_by_xpath("//div[@class='isgrP']")
self.driver.execute_script('arguments[0].scrollTop = arguments[0].scrollTop + arguments[0].offsetHeight;',
following_panel)
try:
ul = self.driver.find_element_by_xpath("""/html/body/div[5]/div/div/div[2]/ul""")
except NoSuchElementException:
ul = self.driver.find_element_by_xpath("""/html/body/div[4]/div/div/div[2]/ul""")
li = ul.find_elements_by_tag_name("li")
following_list_ = []
j = 1
for item in li:
if j > num_to_scrape:
break
following_list_.append(item.text.split("\n")[0])
j = j + 1
return following_list_
def unfollow_user(self):
"""
Located on any home page tab
unfollow user
"""
try:
follow_menu_button = WebDriverWait(self.driver, 5).until(
EC.presence_of_element_located((By.XPATH,
"""/html/body/div[1]/section/main/div/header/section/div[1]/div[1]/div/div[2]/div/span/span[1]/button"""))
)
follow_menu_button.click()
except TimeoutException:
follow_menu_button = WebDriverWait(self.driver, 5).until(
EC.presence_of_element_located((By.XPATH,
"""/html/body/div[1]/section/main/div/header/section/div[1]/div[1]/div/div[3]/div/span/span[1]/button"""))
)
follow_menu_button.click()
try:
unfollow_button = WebDriverWait(self.driver, 5).until(
EC.presence_of_element_located((By.XPATH, """/html/body/div[5]/div/div/div/div[3]/button[1]"""))
)
unfollow_button.click()
return True
except TimeoutException:
try:
unfollow_button = WebDriverWait(self.driver, 5).until(
EC.presence_of_element_located((By.XPATH, """/html/body/div[4]/div/div/div/div[3]/button[1]"""))
)
unfollow_button.click()
return True
except TimeoutException:
return False
return False
def follow_user(self):
"""
located on any home page tab
follow user
"""
WebDriverWait(self.driver, 4).until(
EC.presence_of_element_located(
(By.XPATH, """/html/body/div[1]/section/main"""))
)
option1 = False
option2 = False
if len(self.driver.find_elements_by_xpath(
"""/html/body/div[1]/section/main/div/header/section/div[1]/div[1]/div/div/button""")) > 0:
option1 = True
elif len(self.driver.find_elements_by_xpath(
"""/html/body/div[1]/section/main/div/header/section/div[1]/div[1]/div/div/div/span/span[1]/button""")) > 0:
option2 = True
else:
return False
if option1:
follow_button = self.driver.find_element_by_xpath(
"""/html/body/div[1]/section/main/div/header/section/div[1]/div[1]/div/div/button""")
if follow_button.text == "Follow" or follow_button.text == "Follow Back":
follow_button.click()
return True
else:
return False
elif option2:
follow_button = self.driver.find_element_by_xpath(
"""/html/body/div[1]/section/main/div/header/section/div[1]/div[1]/div/div/div/span/span[1]/button""")
if follow_button.text == "Follow" or follow_button.text == "Follow Back":
follow_button.click()
return True
else:
return False
return False
# /html/body/div[1]/section/main/div/header/section/div[1]/div[1]/div/div/button
# /html/body/div[1]/section/main/div/header/section/div[1]/div[1]/div/div/div/span/span[1]/button
# /html/body/div[1]/section/main/div/header/section/div[1]/div[1]/div/div[2]/div/span/span[1]/button ako veche go sledvam
# /html/body/div[1]/section/main/div/header/section/div[1]/div[1]/div/div/div/span/span[1]/button ako nito toi me nito az nego
# /html/body/div[1]/section/main/div/header/section/div[1]/div[1]/div/div/div/span/span[1]/button ako toi me sledva az nego ne
class UnfollowUsers(InstagramBot):
def read_all_user_followings(self, user):
"""
:param user: user to scrape
:return: full list of followings
"""
self.navigate_to_home_page(user)
all_user_followings = self.get_following(-1)
return all_user_followings
def check_if_user_follows_back(self, user):
"""
:param user: user to check
:return: True if following back
False if not
"""
try:
user_list = self.read_all_user_followings(user)
except:
print("check_if_user_follows_back bate except chasta")
return False
if self.username in user_list:
return True
else:
return False
def start_unfollowing(self, num_to_unfollow, max_to_check=-1):
""""
:param num_to_unfollow: max_users to unfollow
:param max_to_check: max follows the users to have
if max_to_check == -1 doesn't check
for the program to check if he is following back
scans num_to_unfollow * 10
"""
num_unfollowed = 0
while num_to_unfollow > num_unfollowed:
self.navigate_to_home_page()
following_list = self.get_following(num_to_unfollow * 10)
random.shuffle(following_list)
for user in following_list:
if max_to_check == -1:
if not self.check_if_user_follows_back(user):
self.navigate_to_home_page(user)
if self.unfollow_user():
num_unfollowed = num_unfollowed + 1
self.my_logger.log_unfollow(user)
if num_unfollowed >= num_to_unfollow:
return
elif max_to_check > 0:
self.navigate_to_home_page(user)
num_of_following = self.get_following_number()
if num_of_following > max_to_check:
time.sleep(random.randint(2, 4))
self.navigate_to_home_page(user)
if self.unfollow_user():
num_unfollowed = num_unfollowed + 1
self.my_logger.log_unfollow(user)
if num_unfollowed >= num_to_unfollow:
return
time.sleep(random.randint(2, 4))
else:
if not self.check_if_user_follows_back(user):
self.navigate_to_home_page(user)
if self.unfollow_user():
num_unfollowed = num_unfollowed + 1
self.my_logger.log_unfollow(user)
if num_unfollowed >= num_to_unfollow:
return
# kogato trqbva da unfollowne
# otvarq following taba i preebava sichko kurwata
class FollowUsers(InstagramBot):
def get_random_user(self):
"""
:return: a string that is a username
of a profile to follow from
"""
temp = read_profiles()
username = random.choice(temp)
return username
def open_random_post(self, username):
"""
opens a random post from a given
username homepage. when opened the webpage laods the first 24
without scrolling in lines of 3
"""
choice_list = []
for x in range(1, 9):
for y in range(1, 4):
choice_list.append(
"/html/body/div[1]/section/main/div/div[3]/article/div[1]/div/div[" + str(x) + "]/div[" + str(
y) + "]/a")
self.navigate_to_home_page(username)
try:
image = WebDriverWait(self.driver, 5).until(
EC.presence_of_element_located(
(By.XPATH, random.choice(choice_list)))
)
image.click()
except TimeoutException:
choice_list = []
for x in range(1, 9):
for y in range(1, 4):
choice_list.append(
"/html/body/div[1]/section/main/div/div[2]/article/div[1]/div/div[" + str(x) + "]/div[" + str(
y) + "]/a")
image = WebDriverWait(self.driver, 5).until(
EC.presence_of_element_located(
(By.XPATH, random.choice(choice_list)))
)
image.click()
def scroll(self):
"""
when opened likes panel
scroll some
"""
try:
likes_panel = WebDriverWait(self.driver, 4).until(
EC.presence_of_element_located(
(By.XPATH, """/html/body/div[6]/div/div/div[2]/div"""))
)
except TimeoutException:
likes_panel = WebDriverWait(self.driver, 4).until(
EC.presence_of_element_located(
(By.XPATH, """/html/body/div[5]/div/div/div[2]/div"""))
)
self.driver.execute_script('arguments[0].scrollTop = arguments[0].scrollTop + arguments[0].offsetHeight;',
likes_panel)
def is_eligible_for_follow(self, followers, following):
"""
:return: True of ok to follow
False if not
"""
if followers > 5000 or following > 2500:
# print(1, end=": ")
return False
if following > 1000 and followers < following * 0.5:
# print(2, end=": ")
return False
if followers < 10 or following < 20:
# print(3, end=": ")
return False
flag = False
if float(followers) > following * 1.5:
if followers < 100 and following < followers * 4:
flag = True
if 200 > followers >= 100:
if following < followers * 2:
flag = True
if not flag:
# print(4, end=": ")
return False
return True
def start_following(self, num_to_follow):
"""
once logged in,
open post and start following
people with the checks and all...
"""
num_followed = 0
while num_followed < num_to_follow:
# opens a random post
self.open_random_post(self.get_random_user())
# open likes panel
try:
likes_button = WebDriverWait(self.driver, 4).until(
EC.presence_of_element_located(
(By.XPATH, """/html/body/div[5]/div[2]/div/article/div[3]/section[2]/div/div[2]/button"""))
)
except TimeoutException:
likes_button = WebDriverWait(self.driver, 2).until(
EC.presence_of_element_located(
(By.XPATH, """/html/body/div[4]/div[2]/div/article/div[3]/section[2]/div/div[2]/button"""))
)
likes_button.click()
users_list = []
users_scraped = 0
temp = 1
while users_scraped < num_to_follow:
try:
user_element = WebDriverWait(self.driver, 1).until(
EC.presence_of_element_located(
(By.XPATH, """/html/body/div[6]/div/div/div[2]/div/div/div[""" + str(
temp) + """]/div[2]/div[1]/div/span/a"""))
)
# /html/body/div[6]/div/div/div[2]/div/div/div[1]/div[2]/div[1]/div/span/a
# /html/body/div[5]/div/div/div[2]/div/div/div[1]/div[2]/div[1]/div/span/a
user = user_element.text
if user not in users_list:
users_list.append(user)
users_scraped = users_scraped + 1
temp = temp + 1
except:
temp = 1
self.scroll()
continue
"""
users_list.clear()
users_list = [
"gibbythesmart",
"ll.paradise.voyage.ll",
"_____chillwildlife_____",
"julia_michels_",
"nugie1966",
"p_nath_",
"ray.shizzle"
]
"""
for user in users_list:
self.navigate_to_home_page(user)
if self.is_eligible_for_follow(self.get_followers_number(), self.get_following_number()):
if self.follow_user():
num_followed = num_followed + 1
self.my_logger.log_follow(user)
if num_followed >= num_to_follow:
break
class Simulate(InstagramBot):
def scroll(self, direction=True):
"""
on explore page
scroll some
direction = false:
scroll up
"""
main_panel = self.driver.find_element_by_xpath("/html/body")
if direction:
main_panel.send_keys(Keys.PAGE_DOWN)
else:
main_panel.send_keys(Keys.PAGE_UP)
def simulate(self, num_to_like):
"""
once logged in
simulate scrolling and liking
"""
time.sleep(2)
last_post = ""
num_of_posts_liked = 0
while num_of_posts_liked < num_to_like:
for x in range(4):
self.scroll()
time.sleep(random.randint(1, 2))
article = self.driver.find_element_by_tag_name("article")
links = article.find_elements_by_tag_name("a")
print(links[1].text)
if links[1].text == last_post:
last_post = links[1].text
continue
last_post = links[1].text
if random.randint(3, 4) == 4:
print("sea she likne")
footer_element = article.find_element_by_xpath("div[3]")
buttons = footer_element.find_elements_by_tag_name("button")
flag = False
counter = 0
while not flag and counter < 3:
try:
counter = counter + 1
buttons[0].click()
time.sleep(random.randint(2, 3))
flag = True
self.my_logger.log_like()
num_of_posts_liked = num_of_posts_liked + 1
except ElementClickInterceptedException:
self.scroll(False)
continue
class ReadUnfollowers():
def __init__(self):
pass
def readUnfollowers(self):
self.driver = webdriver.Chrome('C:\chromedriver.exe')
self.driver.get(
"file:///C:/Users/bokov/Desktop/nFollowers%20%E2%80%93%20Instagram%20followers%20tracker%20_%20Dashboard.html")
table = self.driver.find_element_by_xpath("""/html/body/div[3]/div[1]/table""")
for row in table.find_elements_by_tag_name("tr"):
if row.get_attribute("class") != "notfollowed":
continue
i = 0
for td in row.find_elements_by_tag_name("td"):
i = i + 1
if i == 3:
nameElement = td.find_element_by_tag_name("a")
name = nameElement.text
print(name)
def readFile(self):
file = open("unfollowers.txt", "r")
users_list = []
for user in file:
users_list.append(user.strip())
return users_list
def unfollow(self, num, minWait, maxWait):
instagram = InstagramBot(*read_credentials())
instagram.login()
users = self.readFile()
i = 1
for user in users:
instagram.navigate_to_home_page(user)
time.sleep(random.randint(minWait, maxWait))
try:
instagram.unfollow_user()
print(str(i) + " " + user)
time.sleep(random.randint(minWait, maxWait))
i = i + 1
if i == num+1:
break
except TimeoutException:
i = i + 1
print(str(i) + " " + user + " Error")
pass
# "/html/body/div[3]/div[1]/table/tbody/tr[1]/td[5]"
print('Enter num to unfollow: ')
num = int(input())
print('Enter min to wait: ')
minWait = int(input())
print('Enter max to wait: ')
maxWait = int(input())
readUnfollowers = ReadUnfollowers()
# readUnfollowers.readUnfollowers()
readUnfollowers.unfollow(num, minWait, maxWait)
input()
"""
instagram = UnfollowUsers(*read_credentials())
instagram.login()
instagram.start_unfollowing(5, 500)
instagram.driver.quit()
"""
"""
instagram = FollowUsers(*read_credentials())
instagram.login()
instagram.start_following(5)
instagram.driver.quit()
"""
"""
instagram = Simulate(*read_credentials())
instagram.login()
instagram.simulate(3)
"""
"""
instagram = ReadUnfollowers(*read_credentials())
instagram.login()
instagram.readUnfollowers()
"""
"""
1vi probelm - kato scrolva se bugva i ne zarejda sledvashtite
2ri problem - ponqkoga prosto skrolva do dolu i nishto ne prai
(reshenie: dobavi except, koito gi hvashtat logvat gi i produljavat)
!PRAVI GO S IDta I Classove ne sus XPATH !!!!
"""