Skip to content

Added Project that finds people who don't follow you on instagram #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Automation/unfollowers-insta/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# bb8 - Your Personal bot
### Made by [Sarthak Saxena](https://github.com/sarthak1905)
bb8 is a cute name for a great bot to check for the people that you follow who don't follow you back on Instagram.

## How to run
* Install the latest chrome driver and place it in 'C:\Program Files (x86)\chromedriver.exe'. You can download it
from [here] (https://chromedriver.chromium.org/)
* Run the script, enter your username and password for the instagram account.
* That's it. The terminal will soon return you a list of all the accounts that you follow, which don't follow you back.

### Side Note
Do remember to download the dependencies in the requirements.txt file!

## Modules used
* selenium

## Development status
This bot is currently working, as of 3rd October, 2020. However, changes on the Instagram frontend may require
this script to be edited.
147 changes: 147 additions & 0 deletions Automation/unfollowers-insta/insta_bot_bb8.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
from selenium import webdriver
from getpass import getpass
import time

# Class for the bot


class InstaBot:

# Initializes bot
def __init__(self):
self.username = input('Enter your username:')
self.pw = getpass('Enter your password(will NOT appear as you type):')
self.PATH = r"C:\Program Files (x86)\chromedriver.exe"
self.driver = webdriver.Chrome(self.PATH)

# Starts Instagram
def start(self):
self.driver.get('https://www.instagram.com/')
time.sleep(2)
return

# Logs into your account, also closes various dialogue boxes that open on
# the way
def login(self):

user_field = self.driver.find_element_by_xpath(
'//*[@id="loginForm"]/div/div[1]/div/label/input')
pw_field = self.driver.find_element_by_xpath(
'//*[@id="loginForm"]/div/div[2]/div/label/input')
login_button = self.driver.find_element_by_xpath(
'//*[@id="loginForm"]/div/div[3]/button/div')
user_field.send_keys(self.username)
pw_field.send_keys(self.pw)
login_button.click()
time.sleep(2.5)
not_now1 = self.driver.find_element_by_xpath(
'//*[@id="react-root"]/section/main/div/div/div/div/button')
not_now1.click()
time.sleep(2)
not_now2 = self.driver.find_element_by_xpath(
'/html/body/div[4]/div/div/div/div[3]/button[2]')
not_now2.click()
time.sleep(1)
return

# Opens your profile
def open_profile(self):
profile_link = self.driver.find_element_by_xpath(
'//*[@id="react-root"]/section/main/section/div[3]'
'/div[1]/div/div[2]/div[1]/a')
profile_link.click()
time.sleep(2)
return

# Opens the list of the people you follow
def open_following(self):
following_link = self.driver.find_element_by_xpath(
'/html/body/div[1]/section/main/div/header/section/ul/li[3]/a')
following_link.click()
return

# Gets the list of the people you follow
def get_following(self):
xpath = '/html/body/div[4]/div/div/div[2]'
self.following = self.scroll_list(xpath)
return

# Opens the link to 'Followers'
def open_followers(self):
followers_link = self.driver.find_element_by_xpath(
'//*[@id="react-root"]/section/main/div/header/section/ul/li[2]/a')
followers_link.click()
return

# Gets the list of followers
def get_followers(self):
xpath = '/html/body/div[4]/div/div/div[2]'
self.followers = self.scroll_list(xpath)
return

# Scrolls a scroll box and retrieves their names
def scroll_list(self, xpath):

time.sleep(2)
scroll_box = self.driver.find_element_by_xpath(xpath)
last_ht, ht = 0, 1

# Keep scrolling till you can't go down any further
while last_ht != ht:
last_ht = ht
time.sleep(1)
ht = self.driver.execute_script("""
arguments[0].scrollTo(0, arguments[0].scrollHeight);
return arguments[0].scrollHeight;
""", scroll_box)

# Gets the list of accounts
links = scroll_box.find_elements_by_tag_name('a')
names = [name.text for name in links if name.text != '']

# Closes the box
close_btn = self.driver.find_element_by_xpath(
'/html/body/div[4]/div/div/div[1]/div/div[2]/button/div')
close_btn.click()

return names

# Prints the list of people you follow who don't follow you back in
# terminal
def get_unfollowers(self):

self.unfollowers = [
x for x in self.following if x not in self.followers]
for name in self.unfollowers:
print(name)
return

# Closes the driver
def close(self):
self.driver.quit()
return


def main():

# Bot method calls
bb8 = InstaBot()

bb8.start()

bb8.login()

bb8.open_profile()
bb8.open_following()

bb8.get_following()
bb8.open_followers()

bb8.get_followers()
bb8.get_unfollowers()

bb8.close()


if __name__ == '__main__':
main()
2 changes: 2 additions & 0 deletions Automation/unfollowers-insta/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
selenium==3.141.0
urllib3==1.25.10