I'm trying to login to my personnal page with python. But each time I try to login, it looks working but after redirect me to an other login page. I don't understand why? The username and the password dispay good and the login button is turning but always Instagram redirect me to an other Login
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.options import Options
from selenium.common.exceptions import NoSuchElementException
# Configuration des options pour Firefox
options = Options()
options.set_preference("network.cookie.cookieBehavior", 2) # Accepter automatiquement les cookies
# Initialisation du navigateur
browser = webdriver.Firefox(options=options)
# Naviguer vers Instagram
browser.get('https://www.instagram.com/')
# Attendre que la page charge
sleep(5)
# Accepter les cookies si la fenêtre apparaît
try:
cookie_accept_button = browser.find_element(By.XPATH, "//button[text()='Accept All Cookies']") # Sélecteur XPath du bouton de consentement des cookies
cookie_accept_button.click()
except NoSuchElementException:
pass # Ignorer si le bouton de consentement des cookies n'est pas trouvé
# Continuer le processus de connexion
try:
login_link = browser.find_element(By.XPATH, "//a[contains(@href, '/accounts/login/')]") # Rechercher le lien de connexion par le chemin d'accès de l'URL
login_link.click()
except NoSuchElementException:
print("Le lien de connexion n'a pas été trouvé.")
sleep(2)
username_input = browser.find_element(By.CSS_SELECTOR, "input[name='username']")
password_input = browser.find_element(By.CSS_SELECTOR, "input[name='password']")
username_input.send_keys("myusername")
password_input.send_keys("mypassword")
login_button = browser.find_element(By.XPATH, "//button[@type='submit']")
login_button.click()
# Attendre que la connexion soit terminée
sleep(5)
# Fermer le navigateur
#browser.close()