您的位置:首页 >疫情未返校未返工第N天:自动打卡全攻略
发布于2025-08-20 阅读(0)
扫一扫,手机访问
这件事还得从一只蝙蝠说起…
算了,昨天下午3点半,潇X巴哥给我打了个电话,说关于自动打卡的想法…
哎,反正就是因为疫情需要每天向学校提交健康打卡,每天填写相同的内容太麻烦了,所以就想开发一个程序来自动完成打卡…
我和潇X巴哥确定了思路后,分头行动:
他用Java编写了一个后台程序,可以自动为多人打卡,并开发了一个网页让用户填写账号密码并存储在数据库中;我的想法则更直接,只为一个人打卡,用Python模拟浏览器登录后进行打卡,并设置定时任务(多人则设置多个定时任务);在Windows上的运行效果如下:



核心代码如下:
def lajaDaka():
# 登录
r1 = requests.post(login_url, data=login, headers=headers, verify=False)
if r1.status_code == 200:
print(time.strftime("%Y:%m:%d:%H:%M", time.localtime()))
print(login["username"] + " 登录成功!")
# 拿到登录后的 cookie 并添加到 header 中
header1 = r1.headers
headers["Cookie"] = header1["Set-Cookie"]
else:
return
# 打卡
r2 = requests.post(daka_url, data=daka, headers=headers, verify=False)
response2 = r2.json()
if r2.status_code != 200:
print("打卡失败!")
return
if response2["result"] == True:
print("打卡成功!")
else:
print(response2["errorInfoList"]["message"])
if name == "main":
lajaDaka()
自动运行Windows适用的Python代码控制休眠时间如下:
if name == "main":
while True:
now_hour = time.strftime("%H", time.localtime())
now_min = time.strftime("%M", time.localtime())设置每天 8 点发送
if now_hour < "08":
rest = 8 - int(now_hour) + 24
sleeptime = (rest-1)*3600 + (60-int(now_min))*60
print("启动时北京时间为:"+time.strftime("%H:%M", time.localtime()),"\t 脚本将在",rest-1,"小时",int((sleeptime-(rest-1)*3600)/60),"分钟后打卡")
time.sleep(sleeptime)
elif now_hour == "08":
print("软件明天开始将在每天 8 点发送数据!")
lajaDaka()
time.sleep(24*60*60-int(now_min)*60)</code></pre><p>在Linux(云服务器)上搭建Python环境后,下载依赖,使用shell脚本定时执行:</p><pre><code class="language-sh">python /home/python/yiban_daka/daka.py</code></pre><p>CRON表达式的基本语法如下:</p><p>潇X巴哥的Java Web版本符合程序员应有的简洁和方便,干净又卫生! <code>http://39.105.174.214/index.html</code></p>
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
售后无忧
立即购买>office旗舰店
正版软件
正版软件
正版软件
正版软件
正版软件
1
2
3
4
5
6
7
8
9