forked from kingarunesh/100-Days-of-Code-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfollow.py
81 lines (57 loc) · 2.58 KB
/
follow.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
from time import sleep
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
EMAIL = "dlensense" #replace with your username
PASSWORD = "pass123" #replace with your password
MENTOR_USERNAME = "mahi7781" #replace with your targeted insta account username
INSTAGRAM_URL = "https://www.instagram.com/"
chrome_driver_path = r"C:\Users\Hp\Desktop\Bots\INSTAGRAM bot/chromedriver.exe" #replace with your Chromedriver path(better to create folder in that folder code and chromedriver must)
class InstaFollower:
def __init__(self, driver):
self.driver = webdriver.Chrome(service=Service(executable_path=driver))
def login(self, url, email, password):
# open instagram
self.driver.get(url=url)
sleep(5)
# login
email_input = self.driver.find_element(By.NAME, "username")
email_input.send_keys(email)
password_input = self.driver.find_element(By.NAME, "password")
password_input.send_keys(password)
sleep(2)
password_input.send_keys(Keys.ENTER)
sleep(5)
def find_followers(self, url, account):
# get profile
sleep(5)
self.driver.get(url=f"{url}{account}")
sleep(8)
# click on followers
followers = self.driver.find_element(By.CSS_SELECTOR, 'ul.xieb3on li.x2pgyrj a._a6hd')
followers.click()
sleep(7)
#click on followers continuesly by scrolling...
modal = self.driver.find_element(By.XPATH, '/html/body/div[6]/div[1]/div/div[2]/div/div/div/div/div[2]/div/div/div[2]/div[2]/div/div[1]/div/div/div/div[3]/div/button/div/div')
# while True:
for _ in range(2):
sleep(5)
self.driver.execute_script("arguments[0].scrollTop = arguments[0].scrollHeight", modal)
sleep(5)
print("Find followers end")
def follow(self):
print("Follow start")
sleep(5)
# buttons = self.driver.find_elements(By.PARTIAL_LINK_TEXT, "Follow")
buttons = self.driver.find_elements(By.CSS_SELECTOR, "._aano div div button")
print(buttons)
for button in buttons:
button.click()
print(button.text)
sleep(2)
print("Follow end")
bot = InstaFollower(driver=chrome_driver_path)
bot.login(url=INSTAGRAM_URL, email=EMAIL, password=PASSWORD)
bot.find_followers(url=INSTAGRAM_URL, account=MENTOR_USERNAME)
bot.follow()