当前位置:网站首页>图书馆自动预约脚本
图书馆自动预约脚本
2022-07-28 11:33:00 【wechannn】
前言
今年暑假,并没有选择留校的我毅然决然地选择了回家。想着回家躺平,偶尔还能经常去市图书馆卷。
然而,因为疫情防控的要求需要提前一天进行预约才能进入图书馆。当然是必须积极配合遵守规定啦。
但是,图书馆的预约开放时间是每天早上6点钟,作为互联网后浪的我们当然。。。没那么早起床。
于是当我起床打开系统想要预约的时候发现
作为一名勤奋好学的优秀大学生,当然不能被这点小小困难打败,于是乎就有了如题。上车!!!
抓包

市图书馆预约系统是在建立在微信公众号上的。
这里就有第一个坑,这个系统只能在微信客户端上进行访问,而不能在如edge、Firefox、Chrome等浏览器上直接进行访问。
一种方案是在微信开发者工具里面访问进行抓包,但是我是Ubuntu的系统,微信开发者工具还没出Linux版本(差评),只能作罢。
这里采用第二种方案,在手机上进行抓包,iOS和Android自行搜索各大抓包工具。抓取post和get请求的json格式的数据包进行解析。
分析
根据抓包结果分析可知,subLibId和scheduleId的title分别是图书馆的编号和预约时间段的编号。
其他的信息则为一些设备账户校验信息及个人预约登记的信息等等。
模拟
抓包后,使用python编写代码脚本模拟手机微信客户端对目标服务器的节点发送请求。
废话不多说,直接上代码,个人信息用#####代替
import requests
import time
import datetime
import json
# 先创建url 和 headers,然后直接request看行不行。
url = 'https://appointment-backend-cdn.dataesb.com/api/appointment/pub_add/'
header = {
"Accept": "application/json, text/plain, */*",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-CN",
"User-Agent": "#####",
"Referer": "https://appointment-users.dataesb.com/",
"unionid": "#####",
"Content-Length": "173",
"Content-Type": "application/json;charset=UTF-8",
"Origin": "https://appointment-users.dataesb.com",
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-site",
"Connection": "keep-alive",
"Host": "appointment-backend-cdn.dataesb.com"
}
Id = #####
scheduleId_t = #####
def re_exe(inc=20):
global scheduleId_t
while True:
time.sleep(inc)
if datetime.datetime.now().hour == 6:
scheduleId_t += 1
if datetime.datetime.now().hour == 5:
scheduleId_t = #####
post_data = {
"subLibId": Id,
"scheduleId": scheduleId_t,
"children": 0,
"card": "#####",
"cardType": "IDCARD",
"name": "#####",
"phone": "#####",
"childrenConfig": True,
"code": ""
}
time_str_13 = int(float(time.time()) * 1000) # 创建时间戳
param = {
"timestamp": time_str_13,
"callback": "#####"
}
# 然后这样执行就好啦
if datetime.datetime.now().hour == 6:
r1 = requests.post(url, json=post_data, headers=header, params=param, verify=False)
print(scheduleId_t)
print(r1.json())
re_exe(20)
尝试运行,并且将预约的结果打印出来。返回200,并且在日志中能够看到打印的预约结果,完美解决。
END
脚本代码搞定了,也不可能就一直24小时不关电脑让它运行。所以这里需要一台服务器来搞定,刚好我那台还没到期。定时任务,emmm不太会。。。
所以这里让程序在服务器中一直运行,程序执行逻辑是不断循环执行,同时使用了时间函数。上面代码设置了六点一到自动帮我预约每20秒请求一次,防止太频繁把他的数据库打爆还被他发现了。。。
注意,因为scheduleId_t可能会因为图书馆人员后台的设置而进行更改,这里并没有发送解析get请求来更新程序运行中的scheduleId_t,而是通过设置初始化值递增来发送请求。所以初始值需要不定期查看是否需要更改。
使用scp命令,将脚本文件传输到远程服务器上。
scp 脚本路径 服务器路径
最后一个坑!!!终端退出ssh远程连接服务器后,执行的程序也会终止。所以需要将程序在终端持久化运行。用下面命令就可以让程序自动在后台运行,远程连接关闭后也继续运行。
nohup python3 -u *****.py > log.out 2>&1 &
nohup和**&双保险,同时这里将程序所打印的信息保存到日志**中。
使用下面的命令查看是否有进程执行程序。
ps aux
收工,接下来就好好享受暑假图书馆的空调。
边栏推荐
- 奥浦迈生物通过注册:半年营收1.47亿 国寿成达与达晨是股东
- Loongarch Godson architecture document collection
- 安徽京准:北斗卫星同步时钟|北斗同步时钟|NTP网络时钟服务器
- 要想组建敏捷团队,这些方法不可少
- 【vulnhub】presidential1
- Force buckle 7_ 1672. Total assets of the richest customers
- SQL注入 Less24(二次注入)
- Introduction to several methods of keeping two decimal places in PHP
- 产学研用 共建开源人才生态 | 2022 开放原子全球开源峰会教育分论坛圆满召开
- php 日期计算操作处理,当前日期加一天和指定日期减一天
猜你喜欢

Sub database and sub table may not be suitable for your system. Let's talk about how to choose sub database and sub table and newsql

Developing NES game (cc65) 07 and controller with C language

Fusion cloud native, enabling new mileage | 2022 open atom global open source summit cloud native sub forum successfully held

Come to tdengine Developer Conference and have an insight into the future trend of data technology development

行业落地呈现新进展 | 2022 开放原子全球开源峰会 OpenAtom OpenHarmony 分论坛圆满召开

云原生机器学习落地难?灵雀云助力企业快速应用 MLOps

Why do enterprises need the ability of enterprise knowledge management?

开源汇智创未来 | 2022 开放原子全球开源峰会 OpenAtom openEuler 分论坛圆满召开

用C语言开发NES游戏(CC65)09、滚动

产学研用 共建开源人才生态 | 2022 开放原子全球开源峰会教育分论坛圆满召开
随机推荐
If you don't roll the golden nine and silver ten, it's too late
Developing NES games with C language (cc65) 08. Background collision
[try to hack] UDF raises rights
Open source huizhichuang future | 2022 open atom global open source summit openatom openeuler sub forum was successfully held
Developing NES games with C language (cc65) 10. Game cycle
After abolishing Tencent cloud: meiyabaike won the bid of 98.3 million
Newly released, the domestic ide developed by Alibaba is completely open source
php保留两位小数的几种方法介绍
Launcher sample code
【vulnhub】Raven2
SQL注入 Less23(过滤注释符)
【Try to Hack】udf提权
产学研用 共建开源人才生态 | 2022 开放原子全球开源峰会教育分论坛圆满召开
[leetcode] 7. valid anagram · effective letter ectopic words
Configure jupyter remote server
Why do enterprises need the ability of enterprise knowledge management?
Developing NES games with C language (cc65) 04. Complete background
Yolov3 complete explanation - from the perspective of data coding
本地化、低时延、绿色低碳:阿里云正式启用福州数据中心
Laravel $object->updated_ At returns the carbon object. How to return the normal time format