selenium實現疫情簽到

↗я殘夢°發表於2020-12-31

完整程式碼

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

相關文章