刘裕洪的Blog

  • 首页
  • 归档

  • 搜索
leetcode selenium docker 破解 mysql Spring Deepin 逆向 Android Smail 反编译 Linux ThinkPHP jQuery JavaScript html5 css python VMware Centos c# uwp 安朗 校园网 sofether 路由器 交叉编译

python实现自动健康打卡

发表于 2021-01-20 | 0 | 阅读次数 42

脚本

#-*- 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)
    

使用方法

  1. 打开Windows自带的计划任务
    image.png
    2.创建基本任务
    image.png
    触发器选择每天
    image.png
    操作选择启动程序
    程序或脚本选择python安装的绝对路径
    参数填写脚本的绝对路径
    image.png
    点击完成即可
  • 本文作者: 刘裕洪
  • 本文链接: https://liuyuhong.ml/archives/p-y-t-h-o-n-shi-xian-zi-dong-jian-kang-da-ka
  • 版权声明: 本博客所有文章除特别声明外,均采用CC BY-NC-SA 3.0 许可协议。转载请注明出处!
# leetcode # selenium # docker # 破解 # mysql # Spring # Deepin # 逆向 # Android # Smail # 反编译 # Linux # ThinkPHP # jQuery # JavaScript # html5 # css # python # VMware # Centos # c# # uwp # 安朗 # 校园网 # sofether # 路由器 交叉编译
leetcode 01
  • 文章目录
  • 站点概览
刘裕洪

刘裕洪

死宅一只 🎵爱听EDM 📷摄影萌新

28 日志
14 分类
26 标签
RSS
Github E-mail Twitter
Creative Commons
Links
  • Mystery0
  • 梧桐
© 2019 — 2021 刘裕洪
由 Halo 强力驱动
|
主题 - NexT.Mist v5.1.4