使用selenium实现疫情期间体温上报!自动化就是牛逼!

191 阅读1分钟

安装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