使用python selenium模拟登陆163并发送邮件

1、思路1.使用selenium登陆163邮箱
2.自动发送邮件到qq邮箱
2、完整代码from selenium import webdriverfrom selenium.webdriver.common.action_chains import ActionChainsfrom selenium.webdriver.common.by import Byfrom selenium.webdriver import ChromeOptionsimport 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/')#获取iframlogin_iframe = driver.find_element(By.XPATH,'//div[@class="loginWrap"]/div[@id="loginDiv"]/iframe')#切换到iframdriver.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、获取结果 

使用python selenium模拟登陆163并发送邮件

文章插图
 
如果您喜欢本文,就请动动您的发财手为本文点赞评论转发,让我们一起学习更多运维相关知识,最后请记得关注我 。

【使用python selenium模拟登陆163并发送邮件】


    推荐阅读