-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
58 lines (44 loc) · 1.83 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
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import ElementClickInterceptedException
import time
CHROME_DRIVER_PATH = YOUR CHROM DRIVER PATH
SIMILAR_ACCOUNT = "buzzfeedtasty"
USERNAME = YOUR INSTAGRAM USERNAME
PASSWORD = YOUR INSTAGRAM PASSWORD
class InstaFollower:
def __init__(self, path):
self.driver = webdriver.Chrome(executable_path=path)
def login(self):
self.driver.get("https://www.instagram.com/accounts/login/")
time.sleep(5)
username = self.driver.find_element_by_name("username")
password = self.driver.find_element_by_name("password")
username.send_keys(USERNAME)
password.send_keys(PASSWORD)
time.sleep(2)
password.send_keys(Keys.ENTER)
def find_followers(self):
time.sleep(5)
self.driver.get(f"https://www.instagram.com/{SIMILAR_ACCOUNT}")
time.sleep(2)
followers = self.driver.find_element_by_xpath('//*[@id="react-root"]/section/main/div/header/section/ul/li[2]/a')
followers.click()
time.sleep(2)
modal = self.driver.find_element_by_xpath('/html/body/div[4]/div/div/div[2]')
for i in range(10):
self.driver.execute_script("arguments[0].scrollTop = arguments[0].scrollHeight", modal)
time.sleep(2)
def follow(self):
all_buttons = self.driver.find_elements_by_css_selector("li button")
for button in all_buttons:
try:
button.click()
time.sleep(1)
except ElementClickInterceptedException:
cancel_button = self.driver.find_element_by_xpath('/html/body/div[5]/div/div/div/div[3]/button[2]')
cancel_button.click()
bot = InstaFollower(CHROME_DRIVER_PATH)
bot.login()
bot.find_followers()
bot.follow()