使用Python Selenium WebDrive登录到yahoo电子邮件帐户 [英] login to yahoo email account using Python Selenium webdrive

查看:153
本文介绍了使用Python Selenium WebDrive登录到yahoo电子邮件帐户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用带有Python的Selenium登录到yahoo电子邮件帐户.

I need to login to yahoo email account using Selenium with Python.

这是我的代码

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()
driver.get("https://login.yahoo.com")

print driver.current_url

logintxt = driver.find_element_by_name("username")
logintxt.send_keys("email")

pwdtxt = driver.find_element_by_name("passwd")
pwdtxt.send_keys("pass")



button = driver.find_element_by_id("login-signin")
button.click()
driver.get("https://mail.yahoo.com")
print driver.current_url

但是当我打印当前URL时,它总是为我提供登录页面,这意味着它没有登录.

but when I print the current url, it always gives me the login page, which mean that it didn't login.

关于如何解决它的任何想法? 我正在将Centos 6与python 2.6一起使用

any idea about how to fix it ? I'm using Centos 6 with python 2.6

推荐答案

在成功登录后,请等待它(使用WebDriverWait)将您重定向到yahoo主页,然后导航到Yahoo邮箱:

Wait for it (using WebDriverWait) to redirect you to the yahoo main page on successful login before navigating to the Yahoo mail box:

from selenium.webdriver.support.wait import WebDriverWait

button = driver.find_element_by_id("login-signin")
button.click()

# give it time to log in
wait = WebDriverWait(driver, 10)
wait.until(lambda driver: driver.current_url == "https://www.yahoo.com/")

driver.get("https://mail.yahoo.com")

这篇关于使用Python Selenium WebDrive登录到yahoo电子邮件帐户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆