1、思路
1.使用selenium登陸163郵箱
2.自動發送郵件到qq郵箱
2、完整代碼
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver import ChromeOptions
import time
#除掉瀏覽器的識別驗證
option = ChromeOptions()
option.add_experimental_option('excludeSwitches', ['enable-automation'])
option.add_experimental_option("detach", True)
driver = webdriver.Chrome(options=option)
driver.get('https://mail.163.com/')
#獲取ifram
login_iframe = driver.find_element(By.XPATH,'//div[@class="loginWrap"]/div[@id="loginDiv"]/iframe')
#切換到ifram
driver.switch_to.frame(login_iframe)
#點擊賬號輸入
user = driver.find_element(By.XPATH,'//div[@id="account-box"]/div[2]/input')
user.send_keys('chenjinming712@163.com')
#點擊輸入密碼
passwd = driver.find_element(By.XPATH,'//div[@class="inputbox"]/div[2]/input[2]')
passwd.send_keys('xxxxxxx')
login = driver.find_element(By.XPATH,'//div[@class="f-cb loginbox"]/a')
#創建鼠標行為鏈
anctions = ActionChains(driver)
#輸入賬號
anctions.send_keys_to_element(user)
#輸入密碼
anctions.send_keys_to_element(passwd)
#點擊登錄
anctions.move_to_element(login).click()
#提交鼠標行為鏈
anctions.perform()
time.sleep(3)
# 點擊寫信
driver.find_elements(By.CLASS_NAME,"oz0")[1].click()
driver.switch_to.default_content()
# 收件人郵箱
driver.find_elements(By.TAG_NAME,"input")[3].send_keys("565667754@qq.com")
#主題
time.sleep(3)
driver.find_element(By.XPATH,'/html/body/div[2]/div[1]/div/div[1]/section/header/div[2]/div[1]/div/div/input').send_keys('test mail')
# 定位寫信內容框架
driver.switch_to.frame(driver.find_element(By.CLASS_NAME,"App-editor-iframe"))
driver.find_element(By.CLASS_NAME,"nui-scroll").send_keys("你好呀!") # 信息內容
# 點擊發送按鈕
driver.switch_to.default_content()
driver.find_element(By.XPATH,'//div[@class="nui-toolbar-item"]/div/span[2]').click()
time.sleep(2)
# 關閉頁面
driver.quit()
3、獲取結果
如果您喜歡本文,就請動動您的發財手為本文點贊評論轉發,讓我們一起學習更多運維相關知識,最后請記得關注我。