[英]How can I log in to Yahoo FInance using Python Selenium?
我嘗試了以下方式,但是每次單擊登錄中的“下一步”按鈕時,chromdriver 都會打開一個新選項卡並將我重定向到此頁面。
from selenium import webdriver
path = "https://login.yahoo.com/config/login?.src=finance&.intl=us&.lang=en-US&.done=https%3A%2F%2Ffinance.yahoo.com%2Fquotes%2Flogin%2Fview%2Fv1%2F"
option = webdriver.Chrome()
option.add_argument("--incognito")
option.add_argument("--disable-notifications")
browser = webdriver.Chrome("/path/to/chromedriver", optiont=option)
browser.get(path)
browser.find_element_by_name("username").send_keys("username")
# all three attempts below redirected me to the page mentioned above
browser.find_element_by_name("signin").click()
browser.find_element_by_class_name("button-container").click()
browser.find_element_by_id("login-username-form").click()
我想知道這是他們考慮重定向頁面的某種安全措施。
我還嘗試在hidden-input-container
中發送密碼
browser.find_element_by_name("passwd").send_keys("password")
獲取selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
錯誤。 我想我需要在發送密碼之前按下一步按鈕。
我非常感謝在這個問題上的任何幫助。
誘導WebDriverWait
() 並等待element_to_be_clickable
()
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
path = "https://login.yahoo.com/config/login?.src=finance&.intl=us&.lang=en-US&.done=https%3A%2F%2Ffinance.yahoo.com%2Fquotes%2Flogin%2Fview%2Fv1%2F"
option = Options()
option.add_argument("--incognito")
option.add_argument("--disable-notifications")
browser = webdriver.Chrome(executable_path="/path/to/chromedriver",options=option)
browser.get(path)
WebDriverWait(browser,10).until(EC.element_to_be_clickable((By.NAME,"username"))).send_keys("validusername")
WebDriverWait(browser,10).until(EC.element_to_be_clickable((By.NAME,"signin"))).click()
WebDriverWait(browser,10).until(EC.element_to_be_clickable((By.NAME,"password"))).send_keys("password")
WebDriverWait(browser,10).until(EC.element_to_be_clickable((By.ID,"login-signin"))).click()
瀏覽器快照:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.