python3+selenium实现qq邮箱登陆并发送邮件功能
作者:小小小小人ksh 时间:2023-02-04 17:54:23
本文实例为大家分享了python3实现qq邮箱登陆并发送邮件功能的具体代码,供大家参考,具体内容如下
基于selenium,使用chrome浏览器,完成qq邮箱登陆并发送发邮件功能,暂时未封装。qq邮箱和126邮箱登陆还是有一些区别的。
#encoding=utf-8
from selenium import webdriver
import time
#启动chrome浏览器
driver = webdriver.Chrome()
#进入qq邮箱登陆首页
driver.get("https://mail.qq.com/")
time.sleep(1)
#窗口最大化
driver.maximize_window()
#切换到登陆frame(!!!!!!!!必须先切换!!!!!!!!)
driver.switch_to.frame('login_frame')
driver.find_element_by_xpath("//*[@id='switcher_plogin']").click()
time.sleep(3)
#########登陆
#输入用户名
username = driver.find_element_by_xpath("//*[@id='u']")
username.clear()
#将xxxxxxxxxx换成qq邮箱账户
username.send_keys('xxxxxxxxxx')
#输入密码:将1111111111替换为自己的邮箱密码
driver.find_element_by_id('p').send_keys('1111111111')
#点击登陆
driver.find_element_by_id('login_button').click()
time.sleep(10)
#断言登陆成功
assert '退出' in driver.page_source
#########写信
#单击写信按钮
driver.find_element_by_link_text("写信").click()
time.sleep(2)
#切换到mainFrame
driver.switch_to.frame('mainFrame')
time.sleep(2)
#输入收件人
driver.find_element_by_xpath("//*[@id='toAreaCtrl']/div[2]/input").send_keys('123456789@qq.com')
#输入主题
driver.find_element_by_id('subject').send_keys('test')
#输入正文
o=driver.find_elements_by_class_name("qmEditorIfrmEditArea")
o[0].click() #!!!!!!!must click!!!!!!!
o[0].send_keys("abc")
#点击发送按钮
driver.find_element_by_xpath("//*[@id='toolbar']/div/a[1]").click()
time.sleep(3)
##driver.find_element_by_xpath('//a[@name="sendbtn" and @tabindex="9"]').click()
time.sleep(3)
#断言发送成功
assert u"再写一封" in driver.page_source
#关闭浏览器
driver.quit()
小编再为大家分享一段代码:python+selenium自动登录QQ邮箱发送邮件
#coding=utf-8
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
driver = webdriver.Chrome()
url =("https://mail.qq.com/")
name=("874**5483")
key = ("Zly1****612X")
out_name=("65750**8@qq.com")
#
#打开浏览器
driver.get(url)
driver.implicitly_wait(10)
#最大化窗口
driver.maximize_window()
#切换iframe
driver.switch_to.frame("login_frame")
# #定位至账号密码登录
# driver.find_element_by_xpath('//*[@id="switcher_plogin"]').click()
# #账号,密码输入
# driver.find_element_by_xpath('//*[@id="u"]').send_keys(name)
# driver.find_element_by_xpath('//*[@id="p"]').send_keys(key)
# #点击登录
# driver.find_element_by_xpath('//*[@id="login_button"]').click()
#点击头像登录
driver.find_element_by_xpath('//*[@id="img_out_874335483"]').click()
time.sleep(5)
#点击写信
driver.find_element_by_xpath('//*[@id="composebtn"]').click()
time.sleep(3)
#切换iframe至写信
driver.switch_to.frame("mainFrame")
#driver.switch_to.frame(driver.find_element_by_id('mainFrame'))
time.sleep(3)
#添加收件人
driver.find_element_by_xpath('//*[@id="toAreaCtrl"]/div[2]/input').send_keys(out_name)
#添加主题
driver.find_element_by_xpath('//*[@id="subject"]').send_keys("TestCase1")
#退出当前编辑Iframe
driver.switch_to.default_content()
#切换Iframe至编辑正文
driver.switch_to.frame("mainFrame")
#Body_frame=driver.find_element_by_xpath('//iframe[@scrolling="auto"]')
Body_frame=driver.find_element_by_class_name("qmEditorIfrmEditArea")
driver.switch_to.frame(Body_frame)
#添加正文
driver.find_element_by_xpath('/html/body').send_keys("I LOVE Python")
time.sleep(3)
#退回大Frame再点击发送
driver.switch_to.parent_frame()
driver.find_element_by_xpath('//*[@id="toolbar"]/div/a[1]').click()
来源:https://blog.csdn.net/kongsuhongbaby/article/details/83999037
标签:python,qq邮箱,登陆
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python定时任务随机时间执行的实现方法
2023-11-23 18:40:21
flask框架实现连接sqlite3数据库的方法分析
2024-01-21 08:52:38
python扫描proxy并获取可用代理ip的实例
2023-07-29 16:42:50
Python基于Flask框架配置依赖包信息的项目迁移部署
2022-03-26 13:54:56
![](https://img.aspxhome.com/file/2023/9/133829_0s.jpg)
javascript中select下拉框的用法总结
2024-04-19 09:57:51
![](https://img.aspxhome.com/file/2023/2/135992_0s.png)
使用python接入微信聊天机器人
2022-04-08 10:07:23
解决Python requests库编码 socks5代理的问题
2023-01-29 13:27:28
![](https://img.aspxhome.com/file/2023/9/103789_0s.jpg)
百度“有啊”首页首次曝光 以绿色调为主
2008-10-20 12:52:00
![](https://img.aspxhome.com/file/UploadPic/200810/20/20081020125720739s.jpg)
碰到MySQL无法启动1067错误问题解决方法
2024-01-18 09:16:47
![](https://img.aspxhome.com/file/2023/2/105692_0s.jpg)
pytorch + visdom 处理简单分类问题的示例
2022-08-17 12:56:58
![](https://img.aspxhome.com/file/2023/6/121016_0s.jpg)
Python实现随机生成算术题的示例代码
2022-03-30 09:49:38
![](https://img.aspxhome.com/file/2023/3/114533_0s.jpg)
win2008 R2 WEB环境配置之MYSQL 5.6.22安装版安装配置方法
2024-01-25 10:25:17
![](https://img.aspxhome.com/file/2023/8/76458_0s.jpg)
Python获取昨天、今天、明天开始、结束时间戳的方法
2022-08-23 18:23:40
mysql-8.0.15-winx64 使用zip包进行安装及服务启动后立即关闭问题
2024-01-23 05:58:37
![](https://img.aspxhome.com/file/2023/9/108869_0s.jpg)
win2008下mysql8.0.11升级mysql8.0.17版本详细步骤
2024-01-13 18:04:32
![](https://img.aspxhome.com/file/2023/6/128046_0s.png)
python中fastapi设置查询参数可选或必选
2021-11-04 12:25:18
Centos7 安装 PHP7最新版的详细教程
2023-10-16 21:14:12
自定义 Github Action 库实战详解
2022-04-07 13:19:00
MySQL中USING 和 HAVING 用法实例简析
2024-01-14 22:07:47
Go语言中使用flag包对命令行进行参数解析的方法
2024-02-15 00:45:09