Skip to content

Instantly share code, notes, and snippets.

@uluumbch
Created February 24, 2023 02:18
Show Gist options
  • Save uluumbch/3fe5dd7c7860c791d1d2d9be30f13726 to your computer and use it in GitHub Desktop.
Save uluumbch/3fe5dd7c7860c791d1d2d9be30f13726 to your computer and use it in GitHub Desktop.
Auto Follow instagram account from list of link

this is just simple code using python and selenium library for auto following from list given.

Instalation

before using this code, make sure you have python installed and then install selenium using this command line. Open terminal then type: pip install selenium

Running

Last, run app.py and let the magic happen :)

import time
import selenium
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
TIMEOUT = 30
USERNAME = "" # YOUR U7SERANAME HERE
PASSWORD = "" # YOUR PASSWORD HERE
link = []
# open link from txt file, read line by line and apppend it to the list for later use
with open('link.txt', 'r') as f:
templink = f.read().splitlines()
for i in templink:
link.append(i)
options = webdriver.ChromeOptions()
options.add_argument('--no-sandbox')
options.add_argument("--log-level=3")
mobile_emulation = {
"userAgent": "Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/90.0.1025.166 Mobile Safari/535.19"}
options.add_experimental_option("mobileEmulation", mobile_emulation)
# create a new chrome session
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
driver.maximize_window()
# open instagram.com and login using username and password in vairable above
driver.get("https://www.instagram.com/accounts/login/")
time.sleep(1)
wait = WebDriverWait(driver, TIMEOUT)
# get usename input
user_element = wait.until(lambda driver: driver.find_element(By.XPATH,'/html/body/div[2]/div/div/div/div[1]/div/div/div/div[1]/section/main/div[1]/div/div/div[2]/form/div[1]/div[3]/div/label/input'))
# fill username input with username from variable
user_element.send_keys(USERNAME)
# find password input
pass_element = wait.until(lambda driver: driver.find_element(By.XPATH,'/html/body/div[2]/div/div/div/div[1]/div/div/div/div[1]/section/main/div[1]/div/div/div[2]/form/div[1]/div[4]/div/label/input'))
# fill password input
pass_element.send_keys(PASSWORD)
# find login button
login_button = wait.until(lambda driver: driver.find_element(By.XPATH,'/html/body/div[2]/div/div/div/div[1]/div/div/div/div[1]/section/main/div[1]/div/div/div[2]/form/div[1]/div[6]'))
# wait for certain time
time.sleep(0.4)
# then click login button
login_button.click()
time.sleep(10)
# after login succes click link from link list
for i in link:
driver.get(i)
time.sleep(5)
try:
driver.find_element(By.XPATH,"/html/body/div[2]/div/div/div/div[1]/div/div/div/div[1]/div[1]/div[2]/section/main/div/header/section/div[1]/div[1]/div/div/button/div/div").click()
time.sleep(5)
print("followed ", i)
except selenium.common.exceptions.NoSuchElementException:
print("not found link ", i)
continue
time.sleep(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment