这是使用以下代码自动登录Instagram的方法。我正在使用
Selenium 4.14
和 Firefox browser
。
text_box = driver.find_element(by=By.NAME, value="my-text")
或 driver.find_element(by=By.ID, value="email").send_keys("email")
或
email_input = driver.find_element(By.NAME, "email_or_username")
我不知道你真正的问题是什么,因为你没有提到你面临的问题。然而,我只是给你一个 selenium-python 代码来启动浏览器,打开 Instagram 应用程序并将用户名和密码发送到相应的文本框中。希望这有帮助。
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Firefox()
driver.maximize_window()
driver.get("https://www.instagram.com/")
wait = WebDriverWait(driver, 15)
# Click on Allow all cookies button
wait.until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Allow all cookies']"))).click()
# Send text to username textbox
wait.until(EC.element_to_be_clickable((By.NAME, "username"))).send_keys("mic test 123")
# Send text to password textbox
wait.until(EC.element_to_be_clickable((By.NAME, "password"))).send_keys("mic test 456")
结果: