教师端打卡数据自动更新 理论与实践
教师端打卡数据自动更新 理论与实践

教师端打卡数据自动更新 理论与实践

教师端打卡数据自动更新 理论与实践

思路流程

st=>start: 调用chromiumdriver
自动控制chromium
op=>operation: 打开登录页面
输入账号密码并登录
op1=>operation: 调用URL进入
学生日报页面
限制加载时长
time.max = 20s
cond1=>condition: try:
根据未填报按钮
是否正常可使用
判断页面
是否加载成功
op2=>operation: 变量置空
产生班级序号列表
[1,2,3,4]
cond2=>condition: 判断是否存在
未完成打卡班级
op3=>operation: 循环取列表
默认班级序号1~4
op4=>operation: 打开对应班级详细
未完成情况
cond3=>condition: 判断该班级成员
是否全部打卡完成
op5=>operation: 删除对应列表班级值
op6=>operation: 循环取对应学生数
读取学生信息放入变量whj_text中;
cond4=>condition: 是否为最后一名学生
cond5=>condition: 判断当前学生序号
是否为10
op7=>operation: 下一页
cond6=>condition: 判断循环是否结束
op8=>operation: 将变量whj_text
放入html文件中
供公网访问
op9=>operation: 等待片刻
e=>end: 退出chromedriver
运行结束

st->op->op1->cond1
cond1(yes)->op2->cond2
cond1(no)->op1
cond2(yes)->op3->op4->cond3
cond2(no,left)->e
cond3(yes,right)->op5(right)->op3
cond3(no)->op6->cond6
cond6(yes,right)->op8->op9(right)->cond2
cond6(no)->cond4
cond4(yes,right)->op3
cond4(no)->cond5(yes)->op7(left)->op6
cond5(no,left)->op6

代码实现

from selenium import webdriver
import time
#import webbrowser

if __name__ == '__main__':
    while True:
        try:
            wd = webdriver.Chrome('')
            wd.get('http://ihealth.hq.gench.edu.cn/pc/dailys')
            wd.implicitly_wait(10)
            element = wd.find_element_by_id('username')
            element.send_keys('username') #此处username为账号
            element = wd.find_element_by_id('password')
            element.send_keys('password\n') #此处password为密码

            wd.set_page_load_timeout(20)
            while True:
                try:
                    wd.get('http://ihealth.hq.gench.edu.cn/pc/dailys')
                    wd.implicitly_wait(10)
                    wd.find_element_by_css_selector('#q-app > div > div.q-page-container > div > div.q-table__container.q-table--horizontal-separator.q-table__card.q-table--no-wrap.my-sticky-column-table > div.q-table__middle.scroll > table > tbody > tr:nth-child(1) > td:nth-child(12) > button')
                    break
                except:
                    pass

            whj_finish = [1, 2, 3, 4]
            whj_text = ""
            whj_message = ""
            whj = [1, 2, 3, 4]
            while sum(whj_finish) > 0.5:
                for a in whj_finish:
                        wd.find_element_by_css_selector('#q-app > div > div.q-page-container > div > div.q-table__container.q-table--horizontal-separator.q-table__card.q-table--no-wrap.my-sticky-column-table > div.q-table__middle.scroll > table > tbody > tr:nth-child({}) > td:nth-child(12) > button'.format(a)).click()
                        time.sleep(2)
                        try:
                            i = wd.find_element_by_css_selector('body > div.q-dialog.fullscreen.no-pointer-events > div.q-dialog__inner.flex.no-pointer-events.q-dialog__inner--minimized.q-dialog__inner--standard.fixed-full.flex-center > div > div:nth-child(2) > div > div.q-table__bottom.row.items-center.justify-end > div:nth-child(3) > span').text
                            x = int(i[len(i)-2:len(i)])
                            whj_text = whj_text + '\n <p> 专业班级-' + str(a+4) + '<p>'
                            j = 1
                            for c in range(1,x+1):
                                b = wd.find_element_by_css_selector('body > div.q-dialog.fullscreen.no-pointer-events > div.q-dialog__inner.flex.no-pointer-events.q-dialog__inner--minimized.q-dialog__inner--standard.fixed-full.flex-center > div > div:nth-child(2) > div > div.q-table__middle.scroll > table > tbody > tr:nth-child({}) > td:nth-child(3)'.format(j)).text
                                d = wd.find_element_by_css_selector('body > div.q-dialog.fullscreen.no-pointer-events > div.q-dialog__inner.flex.no-pointer-events.q-dialog__inner--minimized.q-dialog__inner--standard.fixed-full.flex-center > div > div:nth-child(2) > div > div.q-table__middle.scroll > table > tbody > tr:nth-child({}) > td:nth-child(7)'.format(j)).text
                                whj_text = whj_text + '\n <p>' + b + d + '<p>'
                                j = j + 1
                                if j == 11:
                                    j = 1
                                    try:
                                        wd.find_element_by_css_selector('body > div.q-dialog.fullscreen.no-pointer-events > div.q-dialog__inner.flex.no-pointer-events.q-dialog__inner--minimized.q-dialog__inner--standard.fixed-full.flex-center > div > div:nth-child(2) > div > div.q-table__bottom.row.items-center.justify-end > div:nth-child(3) > button.q-btn.inline.q-btn-item.non-selectable.q-btn--flat.q-btn--round.text-grey-8.q-focusable.q-hoverable.q-btn--dense > div.q-btn__content.text-center.col.items-center.q-anchor--skip.justify-center.row > i').click()
                                    except:
                                        pass
                        except:
                            whj.remove(a)
                        wd.find_element_by_css_selector('body > div.q-dialog.fullscreen.no-pointer-events > div.q-dialog__inner.flex.no-pointer-events.q-dialog__inner--minimized.q-dialog__inner--standard.fixed-full.flex-center > div > div.q-card__actions.q-card__actions--horiz.row.justify-end > button').click()
                        whj_finish = whj

                whj_message = whj_text
                whj_text = ""
                GEN_HTML = "whj.html"
                #打开文件,准备写入
                f = open(GEN_HTML,'w')
                message = """
                <html>
                <head>未完成打卡情况
                <meta charset="UTF-8" />
                <meta http-equiv="X-UA-Compatible" content="IE=edge" />
                <meta name="viewport" content="width=device-width, initial-scale=1.0" />
                <title>dev.xuanchenbin.com/whj.html</title>
                </head>
                <body>
                <p>每百秒自动更新<p>
                <p>若显示时间与实际时间不对等则为服务器掉线,请速速联系班助!<p>
                %s
                %s
                </body>
                </html>"""%(whj_message,"update at:" + time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime()))

                f.write(message)
                #关闭文件
                f.close()
                time.sleep(100)
            wd.quit()
            break
        except:
            wd.quit()

于20:00之后,点击此处访问展示页面

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注