脚本
#-*- coding:utf-8 -*-
import requests
from lxml import etree
url = "https://hqfw.gzccc.edu.cn/admin/publiz/login.html"
userAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1"
header = {
'User-Agent': userAgent,
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
'Cache-Control': 'no-cache',
'Content-Type': 'application/x-www-form-urlencoded',
'Host': 'hqfw.gzccc.edu.cn',
'Referer': 'https://hqfw.gzccc.edu.cn/admin/publiz/login',
'Origin': 'https://hqfw.gzccc.edu.cn',
'Connection': 'keep-alive'
}
def login(name,password):
postData = {
"name": name,
"password": password,
}
response = requests.post(url, data = postData, headers = header,allow_redirects=False)
#print(f"statusCode = {response.status_code}")
#print(f"text = {response.text}")
cookies = response.cookies
cookie = requests.utils.dict_from_cookiejar(cookies)
return cookie
def getToken(cookie):
responseRes = requests.get('https://hqfw.gzccc.edu.cn/m/jkdk/add.html',cookies=cookie)
#print(f"statusCode = {responseRes.status_code}")
#print(f"text = {responseRes.text}")
html = etree.HTML(responseRes.text)
token = html.xpath('/html/body/div[1]/form/input/@value')[0]
id = html.xpath('/html/body/div[1]/form/div[2]/input[1]/@value')[0]
#print(token)
#print(id)
return token,id
def add(cookie,token,id):
if(len(id)==0):
postData = {
"__token__": token,
"id": "",
"student_name": "1804330222",
"mobile": "15913903966",
"location": "广东省广州市从化区",
"student_health": "0",
"family_health": "0",
"high_risk_area": "0",
}
print("今天是第一次打卡")
else:
postData = {
"__token__": token,
"id": id,
"student_name": "1804330222",
"mobile": "15913903966",
"location": "广东省广州市从化区",
"student_health": "0",
"family_health": "0",
"high_risk_area": "0",
}
print("今天已经打过卡了")
response = requests.post("https://hqfw.gzccc.edu.cn/m/jkdk/add", data = postData,cookies=cookie)
#print(f"statusCode = {response.status_code}")
#print(f"text = {response.text}")
if(response.status_code == 200):
print("健康打卡完成")
else:
print("健康打卡失败")
if __name__ == "__main__":
cookie = login("学号", "密码")
token,id = getToken(cookie)
add(cookie,token,id)
使用方法
- 打开Windows自带的计划任务
2.创建基本任务
触发器选择每天
操作选择启动程序
程序或脚本选择python安装的绝对路径
参数填写脚本的绝对路径
点击完成即可