SEU健康申报+离校请假
Github源码
通过对源码的学习修改,本程序稍作调整,将健康申报、销假和请假模块分开,目前可用。
配置
- chromedriver下载方法,将下载的chromedriver.exe与py程序置于同一目录
- 安装selenium模块
py程序
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from datetime import date, timedelta
import time
import random
import json
import re
chrome_options = Options()
chrome_options.add_argument('–no-sandbox')
chrome_options.add_argument('–disable-dev-shm-usage')
chrome_options.add_experimental_option('excludeSwitches', ['enable-automation'])
chrome_options.add_argument('--start-maximized')
chrome_options.add_argument('--incognito')
chrome_options.add_argument("disable-cache")
chrome_options.add_argument('log-level=3')
chrome_options.add_argument('disable-infobars')
chrome_options.add_argument('--headless')
dailyclock_url = "http://ehall.seu.edu.cn/qljfwapp2/sys/lwReportEpidemicSeu/*default/index.do#/dailyReport"
leave_url = "http://ehall.seu.edu.cn/ygfw/sys/swmxsqjappseuyangong/*default/index.do#/"
def writeLog(text):
with open('log.txt', 'a') as f:
s = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ' ' + text
f.write(s + '\n')
f.close()
def getUserData():
try:
with open("loginData.json", mode='r', encoding='utf-8') as f:
loginData = f.readline()
f.close()
except FileNotFoundError:
print("Welcome to do THE F***ING DAILY JOB automatically in Southeast University")
with open("loginData.json", mode='w', encoding='utf-8') as f:
user = input('输入一卡通号: ')
pw = input('输入密码: ')
details = input('输入请假详情: ')
adress = input('输入详细地址: ')
loginData = {"username": user, "password": pw,
"details": details, "adress": adress, "loc": ""}
loginData = json.dumps(loginData) + '\n'
f.write(loginData)
f.close()
return loginData
def checkTime1():
localtime = time.localtime(time.time())
hour = localtime.tm_hour
if hour >= 15:
return True
else:
return False
def checkTime2():
localtime = time.localtime(time.time())
hour = localtime.tm_hour
if hour >= 16:
return True
else:
return False
def login(user, pw, browser):
browser.get(leave_url)
browser.implicitly_wait(2)
username = browser.find_element(by=By.ID, value='username')
password = browser.find_element(by=By.ID, value='password')
username.clear()
password.clear()
username.send_keys(user)
password.send_keys(pw)
login_button = browser.find_element(by=By.CLASS_NAME, value='auth_login_btn')
login_button.submit()
today_year = date.today().strftime("%Y")
today_month = date.today().strftime("%m")
today_day = date.today().strftime("%d")
tomorrow_year = (date.today() + timedelta(days=1)).strftime("%Y")
tomorrow_month = (date.today() + timedelta(days=1)).strftime("%m")
tomorrow_day = (date.today() + timedelta(days=1)).strftime("%d")
tomorrow = (date.today() + timedelta(days=1)).strftime('%Y-%m-%d')
def dailyDone(browser):
browser.get(dailyclock_url)
browser.implicitly_wait(2)
time.sleep(1)
date_info_raw = browser.find_element(by=By.XPATH,
value="/html/body/div[1]/div/div[1]/div[3]/div/div/div[2]/div[2]/div[1]/div[2]/div/div/div[2]")
date_info = re.findall(r"\d+\.?\d*", date_info_raw.text)
year_info = date_info[0]
month_info = date_info[1]
day_info = date_info[2]
if year_info == today_year and month_info == today_month and day_info == today_day:
return True
else:
return False
def dailyReport(browser):
if checkTime1() == True:
print('注意:规定的今日健康申报最晚时间已过!')
if dailyDone(browser) is True:
print('恭喜,今日已进行过健康申报,如有问题可自行进入学校系统查看!')
elif dailyDone(browser) is False:
print('今日未进行健康申报!')
else:
print('目前是健康申报的时间段,程序即将开始运行')
if dailyDone(browser) is True:
print('恭喜,今日已进行过健康申报!')
time.sleep(1)
elif dailyDone(browser) is False:
print('开始今日健康申报!')
buttons = browser.find_elements_by_css_selector('button')
for button in buttons:
if button.get_attribute("textContent").find("新增") >= 0:
button.click()
browser.implicitly_wait(2)
inputfileds = browser.find_elements_by_tag_name('input')
for i in inputfileds:
if i.get_attribute("placeholder").find("请输入当天晨检体温") >= 0:
i.click()
i.send_keys(str(random.randint(361, 366) / 10.0))
buttons = browser.find_elements_by_tag_name('button')
for button in buttons:
if button.get_attribute("textContent").find("确认并提交") >= 0:
button.click()
buttons = browser.find_elements_by_tag_name('button')
button = buttons[-1]
if button.get_attribute("textContent").find("确定") >= 0:
button.click()
writeLog("今日健康申报成功")
time.sleep(1)
print('恭喜,今日已健康申报已完成!')
else:
print("WARNING: 学校可能改版,请自行进入学校系统查看")
break
break
break
browser.quit()
print("-------------------后台已关闭----------------------")
time.sleep(1)
exit()
else:
browser.close()
print("------------网站出现故障,请稍候重试----------------")
print("-------------------后台已关闭-----------------------")
time.sleep(1)
def checkLeaveCancel(browser):
browser.get(leave_url)
time.sleep(1)
try:
if browser.find_element(by=By.CLASS_NAME, value='mint-button'):
return True
else:
return False
except:
return False
def LeaveCancel(browser):
browser.get(leave_url)
time.sleep(1)
browser.find_element_by_class_name('mint-button').click()
time.sleep(1)
browser.find_element_by_xpath("/html/body/div[1]/div/div/div[5]/button").click()
time.sleep(1)
browser.find_element_by_xpath("/html/body/div[4]/div/div[3]/button[2]").click()
def checkLeave(browser):
try:
browser.get(leave_url)
browser.implicitly_wait(2)
"""
implicitly_wait(): 隐式等待
当使用了隐士等待执行测试的时候,如果 WebDriver 没有在 DOM 中找到元素,将继续等待,超出设定时间后则抛出找不到元素的异常
一旦设置了隐式等待,则它存在整个 WebDriver 对象实例的声明周期中,隐式的等到会让一个正常响应的应用的测试变慢,它会在寻找每个元素的时候都进行等待,这样会增加整个测试执行的时间。
"""
time.sleep(1)
date_info2_raw = browser.find_element(by=By.XPATH, value="/html/body/div[1]/div/div/div[2]/div[1]/div[2]/div")
date_info2 = re.findall(r"\d+\.?\d*", date_info2_raw.text)
year_info2 = date_info2[0]
month_info2 = date_info2[1]
day_info2 = date_info2[2]
if year_info2 == tomorrow_year and month_info2 == tomorrow_month and day_info2 == tomorrow_day:
return True
else:
return False
except:
print("------------网站出现故障,请稍候重试----------------")
return
def checkIfPassed(browser):
time.sleep(1)
print('正在检查明日的请假是否通过...')
browser.get(leave_url)
browser.implicitly_wait(2)
time.sleep(1)
try:
if browser.find_element(By.XPATH, '//html/body/div[1]/div/div/div[2]/div[1]/div[1]/div[2]/div[contains(text(), "已通过")]'):
return True
else:
return False
except:
return False
def IFF():
if checkIfPassed(browser) == True:
print('恭喜明日请假已通过!')
browser.quit()
print('-------------------后台已关闭----------------------')
time.sleep(1)
exit()
else:
print('请假暂未通过,请稍候自行进入学校系统查看!')
browser.quit()
print("-------------------后台已关闭----------------------")
time.sleep(1)
exit()
def askForLeave(browser):
if checkTime2() == True:
print('注意!已超过16:00可能无法请假!')
else:
print('目前是请假的申请时间段!')
ifAskLeave = checkLeave(browser)
if ifAskLeave == True:
print('已申请过明日的请假,即将检查审批是否通过...')
IFF()
elif ifAskLeave == False:
print('未进行明日请假,开始请假!')
browser.get(leave_url)
browser.implicitly_wait(2)
time.sleep(1)
js = "document.querySelector(\"#app > div > div > div.mint-fixed-button.mt-color-white.sjarvhx43.mint-fixed-button--bottom-right.mint-fixed-button--primary.mt-bg-primary\").click();"
browser.execute_script(js)
time.sleep(1)
js = "document.querySelector(\"#CheckCns\").click();"
browser.execute_script(js)
time.sleep(1)
js = "document.querySelector(\"body > div.mint-msgbox-wrapper > div > div.mint-msgbox-btns > button.mint-msgbox-btn.mint-msgbox-confirm.mt-btn-primary\").click();"
browser.execute_script(js)
time.sleep(1)
js = "document.querySelector(\"#app > div > div > div > div.emapm-form > div:nth-child(2) > div > div.mint-cell-group-content.mint-hairline--top-bottom.mt-bg-white.mt-bColor-after-grey-lv5 > div:nth-child(2) > div > a > span\").click();"
browser.execute_script(js)
time.sleep(1)
js = "document.querySelector(\"#app > div > div > div > div.emapm-form > div:nth-child(2) > div > div.mint-cell-group-content.mint-hairline--top-bottom.mt-bg-white.mt-bColor-after-grey-lv5 > div:nth-child(2) > div > div > div.mint-box-group > div > div > div > a:nth-child(1) > div.mint-cell-wrapper.mt-bColor-grey-lv5.mint-cell-no-bottom-line > div.mint-cell-title > label > span.mint-radiobox > span\").click();"
browser.execute_script(js)
time.sleep(1)
js = "document.querySelector(\"#app > div > div > div > div.emapm-form > div:nth-child(2) > div > div.mint-cell-group-content.mint-hairline--top-bottom.mt-bg-white.mt-bColor-after-grey-lv5 > div:nth-child(3) > div > a > span\").click();"
browser.execute_script(js)
time.sleep(1)
js = "document.querySelector(\"#app > div > div > div > div.emapm-form > div:nth-child(2) > div > div.mint-cell-group-content.mint-hairline--top-bottom.mt-bg-white.mt-bColor-after-grey-lv5 > div:nth-child(3) > div > div > div.mint-box-group > div > div > div > a:nth-child(2) > div.mint-cell-wrapper.mt-bColor-grey-lv5.mint-cell-no-bottom-line > div.mint-cell-title > label > span.mint-radiobox > span\").click();"
browser.execute_script(js)
time.sleep(1)
js = "document.querySelector(\"#app > div > div > div > div.emapm-form > div:nth-child(2) > div > div.mint-cell-group-content.mint-hairline--top-bottom.mt-bg-white.mt-bColor-after-grey-lv5 > div:nth-child(5) > div > a > span\").click();"
browser.execute_script(js)
time.sleep(1)
js = "document.querySelector(\"#app > div > div > div > div.emapm-form > div:nth-child(2) > div > div.mint-cell-group-content.mint-hairline--top-bottom.mt-bg-white.mt-bColor-after-grey-lv5 > div:nth-child(5) > div > div > div.mint-box-group > div > div > div > a:nth-child(3) > div.mint-cell-wrapper.mt-bColor-grey-lv5.mint-cell-no-bottom-line > div.mint-cell-title > label > span.mint-radiobox > span\").click();"
browser.execute_script(js)
time.sleep(1)
js = "document.querySelector(\"#app > div > div > div > div.emapm-form > div:nth-child(2) > div > div.mint-cell-group-content.mint-hairline--top-bottom.mt-bg-white.mt-bColor-after-grey-lv5 > div:nth-child(6) > div > a \").click();"
browser.execute_script(js)
time.sleep(1)
js = "document.querySelector(\"#app > div > div > div > div.emapm-form > div:nth-child(2) > div > div.mint-cell-group-content.mint-hairline--top-bottom.mt-bg-white.mt-bColor-after-grey-lv5 > div:nth-child(6) > div > div.mint-popup.mt-bg-white.mint-datetime.emapm-date-picker.mint-popup-bottom > div > div.mint-picker__columns > div:nth-child(1) > ul > li:nth-child(" + str(
int(tomorrow_year) - 1921) + ")\").click();"
browser.execute_script(js)
time.sleep(1)
js = "document.querySelector(\"#app > div > div > div > div.emapm-form > div:nth-child(2) > div > div.mint-cell-group-content.mint-hairline--top-bottom.mt-bg-white.mt-bColor-after-grey-lv5 > div:nth-child(6) > div > div.mint-popup.mt-bg-white.mint-datetime.emapm-date-picker.mint-popup-bottom > div > div.mint-picker__columns > div:nth-child(2) > ul > li:nth-child(" + tomorrow_month + ")\").click();"
browser.execute_script(js)
time.sleep(1)
js = "document.querySelector(\"#app > div > div > div > div.emapm-form > div:nth-child(2) > div > div.mint-cell-group-content.mint-hairline--top-bottom.mt-bg-white.mt-bColor-after-grey-lv5 > div:nth-child(6) > div > div.mint-popup.mt-bg-white.mint-datetime.emapm-date-picker.mint-popup-bottom > div > div.mint-picker__columns > div:nth-child(3) > ul > li:nth-child(" + tomorrow_day + ")\").click();"
browser.execute_script(js)
time.sleep(1)
js = "document.querySelector(\"#app > div > div > div > div.emapm-form > div:nth-child(2) > div > div.mint-cell-group-content.mint-hairline--top-bottom.mt-bg-white.mt-bColor-after-grey-lv5 > div:nth-child(6) > div > div.mint-popup.mt-bg-white.mint-datetime.emapm-date-picker.mint-popup-bottom > div > div.mint-picker__columns > div:nth-child(4) > ul > li:nth-child(1)\").click();"
browser.execute_script(js)
time.sleep(1)
js = "document.querySelector(\"#app > div > div > div > div.emapm-form > div:nth-child(2) > div > div.mint-cell-group-content.mint-hairline--top-bottom.mt-bg-white.mt-bColor-after-grey-lv5 > div:nth-child(6) > div > div.mint-popup.mt-bg-white.mint-datetime.emapm-date-picker.mint-popup-bottom > div > div.mint-picker__columns > div:nth-child(5) > ul > li:nth-child(17)\").click();"
browser.execute_script(js)
time.sleep(1)
js = "document.querySelector(\"#app > div > div > div > div.emapm-form > div:nth-child(2) > div > div.mint-cell-group-content.mint-hairline--top-bottom.mt-bg-white.mt-bColor-after-grey-lv5 > div:nth-child(6) > div > div.mint-popup.mt-bg-white.mint-datetime.emapm-date-picker.mint-popup-bottom > div > div.mint-picker__toolbar.mt-bColor-grey-lv6 > div.mint-picker__confirm.mt-color-theme\").click();"
browser.execute_script(js)
time.sleep(1)
js = "document.querySelector(\"#app > div > div > div > div.emapm-form > div:nth-child(2) > div > div.mint-cell-group-content.mint-hairline--top-bottom.mt-bg-white.mt-bColor-after-grey-lv5 > div:nth-child(7) > div > a\").click();"
browser.execute_script(js)
time.sleep(1)
js = "document.querySelector(\"#app > div > div > div > div.emapm-form > div:nth-child(2) > div > div.mint-cell-group-content.mint-hairline--top-bottom.mt-bg-white.mt-bColor-after-grey-lv5 > div:nth-child(7) > div > div.mint-popup.mt-bg-white.mint-datetime.emapm-date-picker.mint-popup-bottom > div > div.mint-picker__columns > div:nth-child(1) > ul > li:nth-child(" + str(
int(tomorrow_year) - 1921) + ")\").click();"
browser.execute_script(js)
time.sleep(1)
js = "document.querySelector(\"#app > div > div > div > div.emapm-form > div:nth-child(2) > div > div.mint-cell-group-content.mint-hairline--top-bottom.mt-bg-white.mt-bColor-after-grey-lv5 > div:nth-child(7) > div > div.mint-popup.mt-bg-white.mint-datetime.emapm-date-picker.mint-popup-bottom > div > div.mint-picker__columns > div:nth-child(2) > ul > li:nth-child(" + tomorrow_month + ")\").click();"
browser.execute_script(js)
time.sleep(1)
js = "document.querySelector(\"#app > div > div > div > div.emapm-form > div:nth-child(2) > div > div.mint-cell-group-content.mint-hairline--top-bottom.mt-bg-white.mt-bColor-after-grey-lv5 > div:nth-child(7) > div > div.mint-popup.mt-bg-white.mint-datetime.emapm-date-picker.mint-popup-bottom > div > div.mint-picker__columns > div:nth-child(3) > ul > li:nth-child(" + tomorrow_day + ")\").click();"
browser.execute_script(js)
time.sleep(1)
js = "document.querySelector(\"#app > div > div > div > div.emapm-form > div:nth-child(2) > div > div.mint-cell-group-content.mint-hairline--top-bottom.mt-bg-white.mt-bColor-after-grey-lv5 > div:nth-child(7) > div > div.mint-popup.mt-bg-white.mint-datetime.emapm-date-picker.mint-popup-bottom > div > div.mint-picker__columns > div:nth-child(4) > ul > li:nth-child(24)\").click();"
browser.execute_script(js)
time.sleep(1)
js = "document.querySelector(\"#app > div > div > div > div.emapm-form > div:nth-child(2) > div > div.mint-cell-group-content.mint-hairline--top-bottom.mt-bg-white.mt-bColor-after-grey-lv5 > div:nth-child(7) > div > div.mint-popup.mt-bg-white.mint-datetime.emapm-date-picker.mint-popup-bottom > div > div.mint-picker__columns > div:nth-child(5) > ul > li:nth-child(53)\").click();"
browser.execute_script(js)
time.sleep(1)
js = "document.querySelector(\"#app > div > div > div > div.emapm-form > div:nth-child(2) > div > div.mint-cell-group-content.mint-hairline--top-bottom.mt-bg-white.mt-bColor-after-grey-lv5 > div:nth-child(7) > div > div.mint-popup.mt-bg-white.mint-datetime.emapm-date-picker.mint-popup-bottom > div > div.mint-picker__toolbar.mt-bColor-grey-lv6 > div.mint-picker__confirm.mt-color-theme\").click();"
browser.execute_script(js)
time.sleep(1)
input_box = browser.find_element(by=By.XPATH,
value="/html/body/div[1]/div/div/div/div[1]/div[2]/div/div[2]/div[9]/div/a/div[2]/div[2]/div[1]/textarea")
try:
input_box.send_keys(details)
print('正在填写请假详情...')
except Exception as e:
print('fail')
time.sleep(1)
js = "document.querySelector(\"#app > div > div > div > div.emapm-form > div:nth-child(2) > div > div.mint-cell-group-content.mint-hairline--top-bottom.mt-bg-white.mt-bColor-after-grey-lv5 > div:nth-child(12) > div > a > span \").click();"
browser.execute_script(js)
time.sleep(1)
js = "document.querySelector(\"#app > div > div > div > div.emapm-form > div:nth-child(2) > div > div.mint-cell-group-content.mint-hairline--top-bottom.mt-bg-white.mt-bColor-after-grey-lv5 > div:nth-child(12) > div > div > div.mint-box-group > div > div > div > a:nth-child(1) > div.mint-cell-wrapper.mt-bColor-grey-lv5.mint-cell-no-bottom-line > div.mint-cell-title > div > label > span.mint-checkbox-new\").click();"
browser.execute_script(js)
time.sleep(1)
js = "document.querySelector(\"#app > div > div > div > div.emapm-form > div:nth-child(2) > div > div.mint-cell-group-content.mint-hairline--top-bottom.mt-bg-white.mt-bColor-after-grey-lv5 > div:nth-child(12) > div > div > div.mint-selected-footer.__emapm > div.mint-selected-footer-bar > button.mint-button.mint-selected-footer-confirm.mt-btn-primary.mint-button--large\").click();"
browser.execute_script(js)
time.sleep(1)
js = "document.querySelector(\"#app > div > div > div > div.emapm-form > div:nth-child(2) > div > div.mint-cell-group-content.mint-hairline--top-bottom.mt-bg-white.mt-bColor-after-grey-lv5 > div:nth-child(13) > div > a \").click();"
browser.execute_script(js)
time.sleep(1)
js = "document.querySelector(\"#app > div > div > div > div.emapm-form > div:nth-child(2) > div > div.mint-cell-group-content.mint-hairline--top-bottom.mt-bg-white.mt-bColor-after-grey-lv5 > div:nth-child(13) > div > div > div.mint-box-group > div > div > div > a:nth-child(2) > div.mint-cell-wrapper.mt-bColor-grey-lv5.mint-cell-no-bottom-line > div.mint-cell-title > label\").click();"
browser.execute_script(js)
time.sleep(1)
input_box = browser.find_element(by=By.XPATH,
value="/html/body/div[1]/div/div/div/div[1]/div[2]/div/div[2]/div[21]/div/a/div[2]/div[2]/input")
try:
input_box.send_keys(adress)
except Exception as e:
print('申请失败!')
time.sleep(1)
js = "document.querySelector(\"#app > div > div > div > div.mint-layout-container.sjakudbpe.OPjb4dozyy > button\").click();"
browser.execute_script(js)
time.sleep(1)
writeLog("明日请假申报成功")
print("已完成明日请假!")
IFF()
else:
browser.close()
print("------------网站出现故障,后台已关闭----------------")
time.sleep(1)
if __name__ == "__main__":
userData = getUserData()
loginData = json.loads(str(userData).strip())
user = loginData['username']
pw = loginData['password']
details = loginData['details']
adress = loginData['adress']
browser_loc = loginData['loc']
if len(browser_loc) > 10:
chrome_options.binary_location = browser_loc
print("Welcome to this Program which can Automatically Do THE F***ING DAILY JOB of Southeast University")
S = str(input("进行健康申报,请输入'Y'继续;销除请假记录,请输入'X'继续;进行明日请假,请输入'Z'继续;输入'N'退出本次操作: "))
try:
if S == "N":
print('本次运行结束,本窗口将在1秒后自动关闭,再见!')
time.sleep(1)
exit(0)
elif S == "Y":
service = Service("chromedriver.exe")
browser = webdriver.Chrome(service=service)
print("------------------已启动,后台运行中----------------------")
login(user, pw, browser)
browser.implicitly_wait(2)
dailyReport(browser)
browser.quit()
print("-------------------后台已关闭----------------------")
time.sleep(1)
exit()
elif S == "X":
service = Service("chromedriver.exe")
browser = webdriver.Chrome(service=service)
print("------------------已启动,后台运行中----------------------")
login(user, pw, browser)
browser.implicitly_wait(2)
while checkLeaveCancel(browser) == True:
print('有未销假记录,正在销假...')
LeaveCancel(browser)
time.sleep(1)
print("已申请销假,销假可能需学校人工审核!")
browser.close()
print("-----------------------后台已关闭-------------------------")
time.sleep(10)
elif S == "Z":
service = Service("chromedriver.exe")
browser = webdriver.Chrome(service=service)
print("------------------已启动,后台运行中----------------------")
login(user, pw, browser)
browser.implicitly_wait(2)
askForLeave(browser)
browser.quit()
print("-------------------后台已关闭----------------------")
time.sleep(1)
exit()
except:
browser.quit()
print("------------网站出现故障,请稍候重试----------------")
print("-------------------后台已关闭-----------------------")
time.sleep(1)
exit()
后记
selenium学习手册
记录一下,笔者后期也会慢慢学习!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)