python3+selenium實(shí)現(xiàn)126郵箱登陸并發(fā)送郵件功能
更新時間:2019年01月23日 10:15:10 作者:小小小小人ksh
這篇文章主要為大家詳細(xì)介紹了python3+selenium實(shí)現(xiàn)126郵箱登陸并發(fā)送郵件功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了python3實(shí)現(xiàn)126郵箱登陸并發(fā)送郵件的具體代碼,供大家參考,具體內(nèi)容如下
基于selenium,使用chrome瀏覽器,完成126郵箱登陸并發(fā)送發(fā)郵件功能,暫時未封裝。
from selenium import webdriver # 導(dǎo)入顯示等待類 from selenium.webdriver.support.ui import WebDriverWait # 導(dǎo)入期望場景類 from selenium.webdriver.support import expected_conditions as EC # 導(dǎo)入By類 from selenium.webdriver.common.by import By import time #瀏覽器驅(qū)動放在了c:\\Python36\\Scripts目錄下,無需指定參數(shù) driver= webdriver.Chrome() driver.get("https://mail.126.com/") time.sleep(3) ####登陸 driver.switch_to.frame("x-URS-iframe") user_name = driver.find_element_by_xpath('//*[@name="email"]') #將xxxxxxx替換為自己的用戶名 user_name.send_keys('xxxxxxx') pass_word = driver.find_element_by_xpath('//*[@name="password"]') #將11111111111替換為自己的密碼 pass_word.send_keys('11111111111') button = driver.find_element_by_id("dologin") button.click() driver.switch_to.default_content() time.sleep(3) ####寫郵件 wait = WebDriverWait(driver,10,0.2) ##wait.until(EC.visibility_of_element_located((By.XPATH,"http://span[text()='發(fā)送']"))) wait.until(EC.visibility_of_element_located((By.XPATH,"http://a[contains(text(),'退出')]"))) driver.find_element_by_xpath('//span[text()="寫 信"]').click() driver.find_element_by_xpath('//input[@tabindex="1" and @role="combobox"]').\ send_keys("1234h@qq.com") driver.find_element_by_xpath('//input[@tabindex="1" and @class="nui-ipt-input"]').\ send_keys("測試郵件") driver.find_element_by_xpath('//input[@type="file"]').send_keys("f:\\b.txt") time.sleep(5) wait.until(EC.visibility_of_element_located((By.XPATH,"http://span[text()='上傳完成']"))) driver.switch_to.frame(driver.find_element_by_xpath('//iframe[@tabindex=1]')) driver.execute_script("document.getElementsByTagName('body')[0].innerHTML='<b>郵件的正文內(nèi)容<b>;'") driver.switch_to.default_content() ##發(fā)送 driver.find_element_by_xpath('//span[text()="發(fā)送"]').click() time.sleep(5) assert '發(fā)送成功' in driver.page_source logout_link=driver.find_element_by_xpath("http://a[text()='退出']") time.sleep(3) assert u"登錄" in driver.page_source driver.quit()
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
tensorflow轉(zhuǎn)onnx的實(shí)現(xiàn)方法
本文主要介紹了tensorflow轉(zhuǎn)onnx的實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-03-03Python實(shí)現(xiàn)拉格朗日插值法的示例詳解
插值法是一種數(shù)學(xué)方法,用于在已知數(shù)據(jù)點(diǎn)(離散數(shù)據(jù))之間插入數(shù)據(jù),以生成連續(xù)的函數(shù)曲線,而格朗日插值法是一種多項式插值法。本文就來用Python實(shí)現(xiàn)拉格朗日插值法,希望對大家有所幫助2023-02-02使用Python一鍵提取PDF中的表格到Excel的方法詳解
從PDF文件獲取表格中的數(shù)據(jù),也是日常辦公容易涉及到的一項工作,一個一個復(fù)制吧,效率確實(shí)太低了,用Python從PDF文檔中提取表格數(shù)據(jù),并寫入Excel文件,灰?;页8咝?本文就給大家介紹一下如何使用Python一鍵提取PDF中的表格到Excel,需要的朋友可以參考下2023-08-08解決import tensorflow as tf 出錯的原因
這篇文章主要介紹了解決import tensorflow as tf 出錯的原因,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-04-04關(guān)于tf.reverse_sequence()簡述
今天小編就為大家分享一篇關(guān)于tf.reverse_sequence()簡述,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-01-01