1.使用selenium登陆163邮箱
2.自动发送邮件到qq邮箱
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()
如果您喜欢本文,就请动动您的发财手为本文点赞评论转发,让我们一起学习更多运维相关知识,最后请记得关注我。