python脚本-淮海工学院图书馆座位预订

分析

分析步骤

  • 微信公众号关注淮海工学院图书馆
  • 点击我的图书馆
  • 点击座位预约
  • 点击手机右上角的分享,复制链接淮海工学院图书馆座位预定登陆界面
  • 用电脑端登陆,发现有些控件不显示,不能进行正常操作
  • 电脑端启用fillder4,为手机设置代理抓包
  • 电脑端启用postman来测试post请求
  • 分析登陆包结构
  • 分析订座包结构
  • 实现自动化订座

操作步骤

  • 微信公众号关注淮海工学院图书馆
    在这里插入图片描述
  • 点击我的图书馆
    在这里插入图片描述
  • 点击座位预约
    在这里插入图片描述
  • 登陆成功
    在这里插入图片描述
  • 点击查找座位
    在这里插入图片描述
  • 选择房间
    在这里插入图片描述
  • 选择座位
    在这里插入图片描述
  • 确认预定
    在这里插入图片描述=
  • 分析登录包
    在这里插入图片描述
  • 分析预定包
    在这里插入图片描述

代码部分

    import requests
    import time
    def login():
        url = "http://seat.hhit.edu.cn/ClientWeb/pro/ajax/login.aspx"
    
        querystring = {"act": "login", "id": "2016121849", "pwd": "2016121849", "role": "512", "aliuserid": "",
                       "schoolcode": "", "wxuserid": "", "_nocache": "1553744928029%0A"}
    
        payload = ""
        headers = {
            'cache-control': "no-cache",
            'Postman-Token': "d0b36b6b-72c4-45b0-b283-4a4c3600bdec"
        }
    
        response = requests.request("GET", url, data=payload, headers=headers, params=querystring)
        print(response.text)
        Cookie = response.cookies.keys()[0] + "=" + response.cookies.values()[0]
        print(Cookie)
        return Cookie
    
    def library(dev_id,start_time,end_time,Cookie):
    
        url = "http://seat.hhit.edu.cn/ClientWeb/pro/ajax/reserve.aspx"
    
        querystring = {"dev_id": dev_id, "lab_id": "100455340", "room_id": "", "kind_id": "100455550", "type": "dev",
                       "prop": "", "test_id": "", "resv_id": "", "term": "", "min_user": "", "max_user": "", "mb_list": "",
                       "test_name": "", "start": start_time, "end": end_time, "memo": "",
                       "act": "set_resv", "_nocache": "1553744312558%0A"}
    
        payload = ""
        headers = {
            'Cookie': Cookie,
            'cache-control': "no-cache",
            'Postman-Token': "f336ab0c-58f8-4089-935b-bd35ad9fb519"
        }
    
        response = requests.request("GET", url, data=payload, headers=headers, params=querystring)
        print(response.json()['msg'])
        return response.json()['msg']
    
    
    def unix_time(dt):
        # 转换成时间数组
        timeArray = time.strptime(dt, "%Y-%m-%d %H:%M:%S")
        # 转换成时间戳
        timestamp = int(time.mktime(timeArray))
        return timestamp
    if __name__=="__main__":
        print("请输入抢课时间,格式如:2019-03-28 14:40:00")
        t=input()
        print("请输入开始时间,格式如:2019-03-28 14:40")
        start_time=input()
        print("请输入结束时间,格式如:2019-03-28 15:40")
        end_time=input()
        t = unix_time(t)-int(time.time())
        print("需睡眠"+str(t)+"秒")
        time.sleep(t)
        dev_id=100455677
        Cookie=login()
        while True:
            #2019-04-03 14:40
            a=library(dev_id,start_time,end_time,Cookie)
            if a=="操作成功!":
                print("抢座成功")
                break
            print("抢座中")
            dev_id+=1
            if dev_id==100455745:
                dev_id=100455677
            time.sleep(1)

小结

欢迎各位评论,看见会一一回复,一起共同进步

猜你喜欢

转载自blog.csdn.net/qq_41860162/article/details/89178215
今日推荐