# 1.导入selenium 包 和 time 包
import time
from selenium import webdriver
# 2.添加个人资料路径 我这里是用谷歌浏览器
user_data = r'--user-data-dir=C:\Users\阿波\AppData\Local\Google\Chrome\User Data'
# 3.将个人资料路径添加到谷歌浏览器加载项中
options = webdriver.ChromeOptions()
options.add_argument(user_data)
# 4.带着加载项打开谷歌浏览器
driver = webdriver.Chrome(options=options)
driver.maximize_window() # 最大化窗口
# 5.访问163邮箱
driver.get('http://mail.163.com/')
# 6.点击写信按钮
driver.find_element_by_xpath("//nav[@class='tT0']/div/ul/li[2]/span[2]").click()
# 7.编辑收件人
# time.sleep(2)
# driver.find_element_by_class_name("nui-editableAddr-ipt").send_keys("ymsdtest@163.com")
driver.find_element_by_class_name("nui-editableAddr-ipt").send_keys("3178711763@qq.com")
# 8.编辑主题
# time.sleep(2)
driver.find_element_by_xpath('//input[@class="nui-ipt-input" and @maxlength="256" and @autocomplete="off"]').send_keys("这是我发送邮件的代码")
# 9.添加附件
# time.sleep(2)
driver.find_element_by_xpath('//input[@class="O0" and @type="file" and @size="1"]').send_keys(文件路径")
# 10.点击发送按钮
driver.find_element_by_xpath('//div[@class="nui-toolbar-item"]/div').click()
# 11.关闭浏览器
# time.sleep(1)
driver.quit()
通过selenium 函自动登录网站并发送邮件
最新推荐文章于 2023-03-26 17:23:11 发布