# clockin
介绍
clockin 吉林大学自动研究生每日打卡
软件架构
- Python 3.8.2 【架构环境,安装不赘述】
- selenium - chromedriver 【调用chrmoe】
开发思路
- 用selenium完成打卡测试,获取网页中“已完成项目”数据,封装成"打卡日志"发送至自己的邮箱,在服务器上创建计划最佳
安装教程
- 将chrmoe驱动存放至 chrome根目录下Application文件夹 【C:\Program Files (x86)\Google\Chrome\Application】
- 新增系统变量 【path C:\Program Files (x86)\Google\Chrome\Application】
- 安装py依赖
修改信息:
username = "#######################" # 账号
pwd = "############################" # 密码
loading_time = 10 # 预留页面加载时间10秒 , 视电脑配置修改
e_mail_host = "smtp.qq.com" # 设置服务器:这个是qq邮箱服务器,直接复制就可以
e_mail_pass = "####################" # 邮箱的授权码
e_sender = 'sender@qq.com' # 发送者的邮箱地址
e_receivers = ['receiver@qq.com'] # 收件人的邮箱地址,可设置为你的QQ邮箱或者其他邮箱,可多个
部署以及运行:
- 复制代码并运行
************** 详细步骤 **************
1.安装chromedriver
1.1 打开chrome浏览器
键入 chrome://version ,查询版本
1.2下载对应版本驱动
下载链接:https://npm.taobao.org/mirrors/chromedriver/(阿里镜像)
1.3 将驱动置于chrome根目录下的Application目录下
1.4 添加系统变量
1.5 获取邮箱授权码
QQ邮箱->设置->账户->POP3/SMTP服务->获取授权码
2.创建计划
2.1 win+R 键入compmgmt.msc 打开计算机管理
2.2创建 clock_in文件夹
2.3创建计划 填入clock_in的filepath
3.修改py文件
3.1 导入py依赖
win+r 调用cmd
# 若报错尝试使用管理员运行cmd 或者 Baidu
pip install selenium
pip install requests
3.2 修改个人信息
username = "#######################" # 账号
pwd = "############################" # 密码
loading_time = 10 # 预留页面加载时间10秒 , 视电脑配置修改
e_mail_host = "smtp.qq.com" # 设置服务器:这个是qq邮箱服务器,直接复制就可以
e_mail_pass = "####################" # 邮箱的授权码
e_sender = 'sender@qq.com' # 发送者的邮箱地址
e_receivers = ['receiver@qq.com'] # 收件人的邮箱地址,可设置为你的QQ邮箱或者其他邮箱,可多个
3.3xpath获取
网页F12,用div id name select 等标签均可获取
4.结果展示
************** 附录 **************
# -*- coding:utf-8 -*-
import time
import smtplib
import os
from selenium import webdriver
from email.mime.text import MIMEText
from email.header import Header
# ========================= 信息-需修改 =========================
username = "#######################" # 账号
pwd = "############################" # 密码
loading_time = 10 # 预留页面加载时间10秒 , 视电脑配置修改
e_mail_host = "smtp.qq.com" # 设置服务器:这个是qq邮箱服务器,直接复制就可以
e_mail_pass = "####################" # 邮箱的授权码
e_sender = 'sender@qq.com' # 发送者的邮箱地址
e_receivers = ['receiver@qq.com'] # 收件人的邮箱地址,可设置为你的QQ邮箱或者其他邮箱,可多个
# ========================= url-无需修改 =========================
login_url = "https://ehall.jlu.edu.cn/jlu_portal/login" # 登录url
submit_url = "https://ehall.jlu.edu.cn/infoplus/form/YJSMRDK/start" # 研究生每日打卡url
remind_url = "https://ehall.jlu.edu.cn/taskcenter/workflow/done" # 已完成事项url
# ========================= xpath-无需修改 =========================
uid_xpath = './/input[@name="username"]' # 账号xpath
pwd_xpath = './/input[@name="password"]' # 密码xpath
button_xpath = './/input[@name="login_submit"]' # 登录按钮xpath
zy_xpath = './/input[@id="V1_CTRL40"]' # 专业
nj_xpath = './/select[@id="V1_CTRL41"]' # 年级
nj2018_xpath = './/select[@id="V1_CTRL41"]/option[10]' # 2018
nj2020_xpath = './/select[@id="V1_CTRL41"]/option[12]' # 2020
xq_xpath = './/select[@id="V1_CTRL42"]' # 校区
zxxq_xpath = './/select[@id="V1_CTRL42"]/option[2]' # 中心校区
sj_xpath= './/input[@id="V1_CTRL67"]' # 手机号
yjsms_xpath = '/html/body/div[4]/form/div/div[3]/div[3]/div[1]/div[1]/div[2]/table/tbody/tr[2]/td/div/table/tbody/tr[5]/td[4]/font/div/div/div/div/input' # 研究生秘书
xw_xpath = './/input[@id="V1_CTRL64"]' # 校外
dzse_xpath = '/html/body/div[4]/form/div/div[3]/div[3]/div[1]/div[1]/div[2]/table/tbody/tr[2]/td/div/table/tbody/tr[11]/td[2]/div/div/div/div/input' # 地址省
dzsi_xpath = '/html/body/div[4]/form/div/div[3]/div[3]/div[1]/div[1]/div[2]/table/tbody/tr[2]/td/div/table/tbody/tr[11]/td[4]/div/div/div/div/input' # 地址市
dzq_xpath = '/html/body/div[4]/form/div/div[3]/div[3]/div[1]/div[1]/div[2]/table/tbody/tr[2]/td/div/table/tbody/tr[11]/td[6]/div/div/div/div/input' # 地址区
dzxx_xpath = './/input[@id="V1_CTRL39"]' # 地址详细
gfxf_xpath = '/html/body/div[4]/form/div/div[3]/div[3]/div[1]/div[1]/div[2]/table/tbody/tr[2]/td/div/table/tbody/tr[12]/td[2]/div/font/div/font[1]/input' # 高风险否
gylmc_xpath = './/select[@id="V1_CTRL7"]' # 公寓楼名称
nybgy_xpath = './/select[@id="V1_CTRL7"]/option[13]' # 南苑8公寓
nylgy_xpath = './/select[@id="V1_CTRL7"]/option[11]' # 南苑6公寓
qsh_xpath = './/input[@id="V1_CTRL8"]' # 寝室号
ss_xpath = './/input[@id="V1_CTRL44"]' # 硕士
bs_xpath = './/input[@id="V1_CTRL45"]' # 博士
q1_xpath = './/input[@id="V1_CTRL28"]' # 7-8
q2_xpath = './/input[@id="V1_CTRL19"]' # 11-12
q3_xpath = './/input[@id="V1_CTRL23"]' # 17-18
confirm_xpath = '/html/body/div[4]/form/div/div[3]/div[3]/div[2]/ul/li/a' # 确认按钮xpath
ok_xpath = './/button[@class="dialog_button default fr"]' # 好按钮xpath
# ========================= 驱动-无需修改 =========================
os.system('taskkill /IM chrome.exe') # 关闭chrome
os.system('taskkill /IM chrome.exe') # 关闭chrome
os.system('taskkill /IM chrome.exe') # 关闭chrome
os.system('taskkill /IM chrome.exe') # 关闭chrome
global driver
driver = webdriver.Chrome() # 设置Chrome驱动
# ========================= 邮箱-无需修改 =========================
class Mail:
def __init__(self):
# 第三方 SMTP 服务
self.mail_host = e_mail_host
self.mail_pass = e_mail_pass
self.sender = e_sender
self.receivers = e_receivers
def send(self, mail_content):
content = mail_content
message = MIMEText(content, 'plain', 'utf-8')
message['From'] = 'zolty@vip.com'
message['To'] = 'YourMajesty@vip.com'
subject = str(time.localtime().tm_hour) + "点打卡" # 发送的主题,可自由填写
message['Subject'] = Header(subject, 'utf-8')
try:
smtpObj = smtplib.SMTP_SSL(self.mail_host, 465)
smtpObj.login(self.sender, self.mail_pass)
smtpObj.sendmail(self.sender, self.receivers, message.as_string())
smtpObj.quit()
print('邮件发送成功')
except smtplib.SMTPException as e:
print('邮件发送失败')
def web_init():
driver.maximize_window() # 最大化窗口
driver.implicitly_wait(6) # 隐式等待
driver.get(login_url) # 获取网页
def web_close():
driver.quit() # 关闭所有关联的窗口
def web_load():
time.sleep(loading_time) # 预留页面加载时间5秒
def auto_login():
web_load()
driver.find_element_by_xpath(uid_xpath).clear() # 清空已存在内容
driver.find_element_by_xpath(uid_xpath).send_keys(username) # 传入用户名
web_load()
driver.find_element_by_xpath(pwd_xpath).clear() # 清空已存在内容
driver.find_element_by_xpath(pwd_xpath).send_keys(pwd) # 传入密码
web_load()
driver.find_element_by_xpath(button_xpath).click() # 通过登录按钮并单击登录
def submit():
driver.get(submit_url) # 获取网页
web_load()
driver.execute_script("window.scrollTo(0,document.body.scrollHeight);") # 将页面滚动条滑到底部
web_load()
driver.find_element_by_xpath(confirm_xpath).click() # 确认填报
web_load()
driver.find_element_by_xpath(ok_xpath).click() # 好
web_load()
def remind():
driver.get(remind_url) # 获取网页
web_load()
row = driver.find_elements_by_tag_name('tr')
result_list = []
for i in row:
j = i.find_elements_by_tag_name('td')
for item in j:
text = item.text
result_list.append(text)
today = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))
return today + '-' + result_list[0] + '-' + result_list[1] + '-' + result_list[2] + '-' + result_list[3]
if __name__ == '__main__':
web_init() # 驱动初始化
auto_login() # 登录操作
submit() # 打卡操作
result_msg = remind() # 获取提醒信息
Mail().send(result_msg)
web_close() # 测试结束