使用selenium實現疫情期間體溫上報!自動化就是牛逼!

爬遍天下無敵手發表於2020-12-09

安裝seleniumm

pip install selenium
  • 1

下載瀏覽器驅動

driver = webdriver.Chrome()#開啟瀏覽器
  • 1

詳細程式碼

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=[['賬號','密碼','QQ郵箱'],]

# print(shuju[0])
for shu in shuju:
    # print (shu)
    hao=shu[0]
    mi=shu[1]
    jie=shu[2]
    
    driver = webdriver.Chrome()
    driver.get("http://hmgr.sec.lit.edu.cn/web/#/login")
    driver.implicitly_wait(10)
    # sleep(6)
    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()
    # 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 = '*******@qq.com'
        #pwd為qq郵箱的授權碼
        pwd = '********' 
        #發件人的郵箱
        sender_qq_mail = '*********@qq.com'
        #收件人郵箱
        receiver = jie

        #郵件的正文內容
        mail_content = '您好,今天的體溫上報已經完成喲,感謝支援'
        #郵件標題
        mail_title = '體溫上報的郵件'

        #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 = '**********@qq.com'
        # #pwd為qq郵箱的授權碼
        # pwd = '*********' ## 
        # #發件人的郵箱
        # sender_qq_mail = '**********@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

相關文章