Skip to content

Commit f529bda

Browse files
authored
Merge pull request #663 from whynesspower/main
Instagram Bot to follow people
2 parents f3658dd + cab01f7 commit f529bda

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed

instagram_follow_bot/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## Instagram Bot to follow people-
2+
3+
**Instagram bot to send a follow request to given set of random people, to increase your reach** -
4+
These type of instagram bots are used extensively by small businesses on Instagram.
5+
6+
### Pre-requisites
7+
8+
1. latest version of chrome
9+
2. Selenium and Instapy module pip installed
10+
11+
### How to Use
12+
instabot2.py uses Instapy module which is much faster then Selenium based bot
13+
14+
15+
***Kindly add your username and password in the code file .***
16+
17+
### Programming Language
18+
19+
- [x] Python
20+

instagram_follow_bot/instabot.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
from selenium import webdriver
2+
from selenium.webdriver.common.by import By
3+
from selenium.webdriver.support.ui import WebDriverWait
4+
from selenium.webdriver.support import expected_conditions as ec
5+
from selenium.webdriver.common.keys import Keys
6+
import time
7+
import csv
8+
9+
already_follow = []
10+
11+
with open('follower.csv', 'r') as csv_file:
12+
csv_reader = csv.reader(csv_file)
13+
for row in csv_reader:
14+
if len(row) != 0:
15+
for element in row:
16+
already_follow.append(element)
17+
18+
19+
class InstagramBot:
20+
def __init__(self, username, password):
21+
self.browser = webdriver.Chrome("chromedriver.exe")
22+
23+
self.username = username
24+
self.password = password
25+
26+
self.browser.delete_all_cookies()
27+
self.browser.maximize_window()
28+
29+
def wait_for_object(self, type, string):
30+
return WebDriverWait(self.browser, 3).until(ec.presence_of_element_located((type, string)))
31+
32+
def wait_for_objects(self, type, string):
33+
return WebDriverWait(self.browser, 3).until(ec.presence_of_all_elements_located((type, string)))
34+
35+
def login(self):
36+
self.browser.get("https://www.instagram.com")
37+
38+
inputs = self.wait_for_objects(By.CSS_SELECTOR, '._2hvTZ.pexuQ.zyHYP')
39+
inputs[0].send_keys(self.username)
40+
inputs[1].send_keys(self.password)
41+
42+
time.sleep(1)
43+
44+
inputs[1].send_keys(Keys.ENTER)
45+
46+
time.sleep(2)
47+
48+
def follow_followers(self, root_name, number_follower):
49+
all_follower = []
50+
51+
time.sleep(2)
52+
53+
self.browser.get(f"https://www.instagram.com/{root_name}/")
54+
55+
time.sleep(2)
56+
57+
followers = self.wait_for_objects(By.CSS_SELECTOR, '._81NM2')
58+
followers[1].click()
59+
60+
for i in range(1, number_follower + 1):
61+
time.sleep(2)
62+
src1 = self.wait_for_object(
63+
By.XPATH, f'/html/body/div[5]/div/div/div[2]/ul/div/li[{i}]')
64+
self.browser.execute_script("arguments[0].scrollIntoView();", src1)
65+
time.sleep(5)
66+
67+
follower_name = src1.text.split()[0]
68+
69+
if follower_name in already_follow:
70+
number_follower += 1
71+
continue
72+
else:
73+
all_follower.append(follower_name)
74+
75+
with open('follower.csv', 'a') as csv_file:
76+
csv_writer = csv.writer(csv_file)
77+
csv_writer.writerow(all_follower)
78+
79+
for follower in all_follower:
80+
self.browser.get(f"https://www.instagram.com/{follower}/")
81+
82+
time.sleep(5)
83+
84+
subscribe_buttons = self.wait_for_objects(
85+
By.XPATH, '//button[text()="Follow"]')
86+
subscribe_buttons[0].click()
87+
88+
time.sleep(5)
89+
90+
91+
bot = InstagramBot(username="enter-your-username-here", password="enter-your-password-here")
92+
bot.login()
93+
# bot.like_hashtag('lifestyle', 3)
94+
bot.follow_followers("therock", 3)

instagram_follow_bot/instabot2.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from instapy import InstaPy
2+
3+
bot = InstaPy(username="enter-your-username-here", password="enter-your-password-here")
4+
bot.login()
5+
bot.set_skip_users(skip_private=False, skip_no_profile_pic=True)
6+
bot.follow_user_followers('nitb.creators', amount=50,
7+
randomize=False, sleep_delay=10)

0 commit comments

Comments
 (0)