someone showed me how to do this in an old video but since Instagram changed I had to go my own way
My Code:
from instagramUserInfo import username, password
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time
class Instagram:
def __init__(self, username,password):
self.browser = webdriver.Chrome()
self.username = username
self.password = password
def signIn(self):
self.browser.get("https://www.instagram.com/accounts/login/")
time.sleep(3)
usernameInput = self.browser.find_element(By.XPATH, '//*[@id="loginForm"]/div/div[1]/div/label/input')
passwordInput= self.browser.find_element(By.XPATH, '//*[@id="loginForm"]/div/div[2]/div/label/input')
usernameInput.send_keys(self.username)
passwordInput.send_keys(self.password)
passwordInput.send_keys(Keys.ENTER)
time.sleep(10)
def getFollowers(self):
self.browser.get(f"https://www.instagram.com/{self.username}")
time.sleep(5)
self.browser.find_element(By.XPATH, '/html/body/div[2]/div/div/div[2]/div/div/div[1]/div[2]/div/div[1]/section/main/div/header/section[3]/ul/li[2]/div/a').click()
time.sleep(5)
followers = self.browser.find_elements(By.CSS_SELECTOR, 'a[role=link]')
for user in followers:
print(user.text)
instgrm = Instagram(username, password)
instgrm.signIn()
instgrm.getFollowers()
When I run, it also pulls unnecessary information and I can’t figure out how to fix it.
I am trying to write a program that, when run, retrieves the Instagram username and password from another file, allows us to log in to Instagram, directs us to the user’s profile and retrieves the follower list. But for now, no scrooling
New contributor
kalpa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.