python——初识Selenium,QQ邮箱登录工具

Python代码:


from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

"""qq邮箱登录工具"""


class QQEmailLogin:
    def __init__(self):
        # 打开firefox浏览器
        self.browser = webdriver.Firefox()
        self.wait = WebDriverWait(self.browser, 20)
        self.browser.get('https://mail.qq.com/')

    def login(self, username, password):
        """
        登录
        :param username:qq账号
        :param password: qq密码
        :return: none
        """
        self.browser.switch_to.frame("login_frame")
        self.text_qq_account = self.wait.until(EC.presence_of_element_located((By.ID, 'u')))
        self.text_qq_password = self.wait.until(EC.presence_of_element_located((By.ID, 'p')))
        self.bt_qq_login = self.wait.until(EC.element_to_be_clickable((By.ID, 'login_button')))
        self.text_qq_account.send_keys(username)
        self.text_qq_password.send_keys(password)
        self.bt_qq_login.click()
        self.browser.switch_to.default_content()
        shoujianxiang = self.wait.until(EC.element_to_be_clickable((By.ID, 'folder_1')))
        shoujianxiang.click()
        self.browser.switch_to.frame("mainFrame")
        em = self.wait.until(
            EC.element_to_be_clickable((By.XPATH, '//div[@id="div_showyesterday"]//table[@class="i M"]')))
        em.click()


if __name__ == '__main__':
    username = input("请输入QQ号:")
    password = input("请输入QQ密码:")
    QQEmailLogin().login(username, password)

程序可能存在部分bug,欢迎交流指正

你可能感兴趣的:(python,python,Selenium)