-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
72 lines (54 loc) · 2.2 KB
/
main.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
'''
# Hamza Mughal's automation script for instagram
================================================
# This bot logs in to instagram and unfollow everyone you follow
# To be used with web
# Tested on Arch Linux with Chromium web browser on 03-29-2020
# Coded while quarntined at home due to corona virus
# more at: https://prodesquare.com
'''
from selenium import webdriver
from time import sleep
from pathlib import Path
from dotenv import load_dotenv
from os import getenv as env
load_dotenv(verbose=True)
class InstagramUnfollowBot:
def __init__(self, username, password):
self.driver = webdriver.Chrome()
self.driver.get(env('LINK_TO_INSTAGRAM'))
sleep(3)
self.driver.find_element_by_name('username').send_keys(env('USERNAME'))
self.driver.find_element_by_name('password').send_keys(env('PASSWORD'))
self.driver.find_element_by_xpath('//button[@type="submit"]').click()
sleep(5)
self.driver.find_element_by_xpath(
"//button[contains(text(), 'Not Now')]").click()
def getFollowings(self):
self.driver.find_element_by_xpath(
"//a[contains(@href, '/{}')]".format(env('USERNAME'))).click()
sleep(2)
self.driver.find_element_by_xpath(
"/html/body/div[1]/section/main/div/header/section/ul/li[3]/a").click()
sleep(2)
scroll_box = self.driver.find_element_by_xpath(
"/html/body/div[4]/div/div[2]")
last_ht, ht = 0, 1
while last_ht != ht:
last_ht = ht
sleep(2)
ht = self.driver.execute_script("""
arguments[0].scrollTo(0, arguments[0].scrollHeight);
return arguments[0].scrollHeight;
""", scroll_box)
unfollow_buttons = scroll_box.find_elements_by_tag_name('button')
for unfollow_button in unfollow_buttons:
sleep(1)
unfollow_button.click()
sleep(1)
self.driver.find_element_by_xpath(
"//button[contains(text(), 'Unfollow')]").click()
print("Instagram Unfollow bot by Hamza Mughal (https://prodesquare.com)")
my_bot = InstagramUnfollowBot(env('USERNAME'), env('PASSWORD'))
my_bot.getFollowings()
sleep(5)