selenium实现疫情签到

完整代码

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from time import sleep
from email.mime.text import MIMEText
from email.header import Header
from smtplib import SMTP_SSL


shuju=[['账户','密码','邮箱'],]
# print(shuju[0])
for shu in shuju:
    # print (shu)
    hao=shu[0]	#学号
    mi=shu[1]	#密码
    jie=shu[2]	#邮箱
    # print(hao)
    # print(mi)
    driver = webdriver.Chrome()	#启动浏览器
    driver.get("http://hmgr.sec.lit.edu.cn/web/#/login")	#访问该网站
    # sleep(2)
    zhanghao = driver.find_element_by_xpath("//input[@placeholder='请输入账号']")	#找到该文本框位置
    zhanghao.send_keys(hao)
    zhanghao.send_keys(Keys.RETURN)
    mima = driver.find_element_by_xpath("//input[@placeholder='请输入密码']")
    mima.send_keys(mi)
    mima.send_keys(Keys.RETURN)
    # sleep(2)
    driver.find_element_by_xpath("//button").click()
    cookie = driver.get_cookies()	#获取当前页面cookie
    # print(cookie)
    sleep(2)
    for coo in cookie:
    	driver.add_cookie(coo)
	# print(coo)
    driver.refresh()	#刷新

    driver.get("http://hmgr.sec.lit.edu.cn/web/#/health")
    sleep(2)


    try:
        driver.find_element_by_xpath("//button").click()
        sleep(2)
        wendu = driver.find_element_by_xpath("//input[@placeholder='腋下温度(小数或整数)']")
        wendu.send_keys("36.5")
        wendu.send_keys(Keys.RETURN)
        driver.find_element_by_xpath("//html/body/div[@id='app']/div[@class='main']/div[@class='dialog_box']/div[@class='main_box']/ul[@class='list_box']/li[3]/div[@class='bottom_btn']/button[@class='ensure_button van-button van-button--default van-button--normal van-button--block']").click()
        sleep(4)
        driver.close() #关闭当前页面

        #qq邮箱smtp服务器
        host_server = 'smtp.qq.com'
        #sender_qq为发件人的qq号码
        sender_qq = '888888@qq.com'
        #pwd为qq邮箱的授权码
        pwd = 'uevtpkamdygigfjf' ## xh**********bdc
        #发件人的邮箱
        sender_qq_mail = '1463749351@qq.com'
        #收件人邮箱
        receiver = jie

        #邮件的正文内容
        mail_content = '您好,今天的体温上报已经完成哟,感谢支持'
        #邮件标题
        mail_title = 'shangbao的邮件'

        #ssl登录
        smtp = SMTP_SSL(host_server)
        #set_debuglevel()是用来调试的。参数值为1表示开启调试模式,参数值为0关闭调试模式
        smtp.set_debuglevel(1)
        smtp.ehlo(host_server)
        smtp.login(sender_qq, pwd)

        msg = MIMEText(mail_content, "plain", 'utf-8')
        msg["Subject"] = Header(mail_title, 'utf-8')
        msg["From"] = sender_qq_mail
        msg["To"] = receiver
        smtp.sendmail(sender_qq_mail, receiver, msg.as_string())
        smtp.quit()


    except :
        driver.close() #关闭当前页面

        #qq邮箱smtp服务器
        host_server = 'smtp.qq.com'
        #sender_qq为发件人的qq号码
        sender_qq = '1463749351@qq.com'
        #pwd为qq邮箱的授权码
        pwd = 'uevtpkamdygigfjf' ## ue**********jf
        #发件人的邮箱
        sender_qq_mail = '1463749351@qq.com'
        #收件人邮箱
        receiver = jie

        #邮件的正文内容
        mail_content = '您好,您还真的很勤快呢'
        #邮件标题
        mail_title = 'shangbao的邮件'

        #ssl登录
        smtp = SMTP_SSL(host_server)
        #set_debuglevel()是用来调试的。参数值为1表示开启调试模式,参数值为0关闭调试模式
        smtp.set_debuglevel(1)
        smtp.ehlo(host_server)
        smtp.login(sender_qq, pwd)

        msg = MIMEText(mail_content, "plain", 'utf-8')
        msg["Subject"] = Header(mail_title, 'utf-8')
        msg["From"] = sender_qq_mail
        msg["To"] = receiver
        smtp.sendmail(sender_qq_mail, receiver, msg.as_string())
        smtp.quit()
        continue
上一篇:mailx


下一篇:Python发送纯文本邮件