Even though my password is correct. I can't log in to Instagram and it gives your password is incorrect error. My intention is to enter Instagram and follow some users automatically. However, I am totally stuck at the login screen. Can the language and connection country be a problem?
from selenium import webdriver
from selenium.webdriver.common.by import By as by
from time import sleep
from selenium.webdriver.common.keys import Keys
URL = "https://www.instagram.com/natgeo/"
URL_LOGIN = "https://www.instagram.com/accounts/login/"
USERNAME = "id"
PASSWORD = 'pass'
class InstaFollower:
def __init__(self):
self.driver = webdriver.Chrome("C:\Selenium\chromedriver.exe")
def login(self):
self.driver.get(URL_LOGIN)
sleep(3)
self.driver.find_element(by.XPATH, '/html/body/div[4]/div/div/button[1]').click()
sleep(5)
for x in USERNAME:
self.driver.find_element(by.CSS_SELECTOR,
'input[aria-label="Telefon numarası, kullanıcı adı veya e-posta"]').send_keys(x)
sleep(.3)
sleep(5)
self.driver.find_element(by.CSS_SELECTOR, 'input[aria-label="Şifre"]').clear()
passy = self.driver.find_element(by.CSS_SELECTOR, 'input[aria-label="Şifre"]')
for i in PASSWORD:
passy.send_keys(i)
sleep(.3)
sleep(5)
passy.send_keys(Keys.ENTER)
sleep(5)
self.driver.find_element(by.CSS_SELECTOR, 'button[class="sqdOP L3NKy y3zKF "]').click()
sleep(5)
self.driver.find_element(by.CSS_SELECTOR, 'button[class="aOOlW HoLwm "]').click()
sleep(5)
self.driver.get(URL)
def find_followers(self):
self.driver.find_element(by.CSS_SELECTOR, 'a[class="-nal3 "]').click()
followers = self.driver.find_elements(by.CSS_SELECTOR, 'button[class="sqdOP L3NKy y3zKF "]')
print(followers)
return followers
def follow(self, followers):
for follower in followers:
follower.click()
print("Followed!")
self.driver.find_element(by.CSS_SELECTOR, 'button[class="wpO6b "]').click()
bot = InstaFollower()
bot.login()
followers = bot.find_followers()
bot.follow(followers)
My Solution:
Password correction was done and after that, I changed the user following algorithm and in the end, it works perfectly but still, there is an improvement chance in which I can follow more people at once. I am going to try to do it in a simple way again but currently have no idea about it. :)
from selenium import webdriver
from selenium.webdriver.common.by import By as by
from time import sleep
from selenium.webdriver.common.keys import Keys
URL = "https://www.instagram.com/natgeo/"
URL_LOGIN = "https://www.instagram.com/accounts/login/"
USERNAME = "id"
PASSWORD = 'pass'
class InstaFollower:
def __init__(self):
self.driver = webdriver.Chrome(executable_path="C:\Selenium\chromedriver.exe")
def login(self):
self.driver.get("https://www.instagram.com/accounts/login/")
sleep(5)
self.driver.find_element(by.XPATH, '/html/body/div[4]/div/div/button[1]').click()
usr = self.driver.find_element(by.CSS_SELECTOR,
'input[aria-label="Telefon numarası, kullanıcı adı veya e-posta"]')
for x in USERNAME:
usr.send_keys(x)
sleep(.1)
sleep(2)
passy = self.driver.find_element(by.CSS_SELECTOR, 'input[aria-label="Şifre"]')
for i in PASSWORD:
passy.send_keys(i)
sleep(.1)
passy.send_keys(Keys.ENTER)
sleep(5)
self.driver.find_element(by.CSS_SELECTOR, 'div.cmbtv').click()
sleep(5)
self.driver.find_element(by.CSS_SELECTOR, 'button.HoLwm').click()
def find_followers(self):
self.driver.get(URL)
self.driver.find_element(by.CSS_SELECTOR, 'a.-nal3').click()
def follow(self):
x=0
sleep(5)
follower_screen=self.driver.find_elements(by.CSS_SELECTOR,'button.sqdOP.L3NKy.y3zKF')
for f in follower_screen:
f.click()
try:
self.driver.find_element(by.CSS_SELECTOR,'button.aOOlW.HoLwm').click()
except:
pass
print("Followed!")
sleep(.7)
bot = InstaFollower()
bot.login()
followers = bot.find_followers()
bot.follow()