不懂先生

代手动座位自动预约程序
序言近段时间不让占座位了,但是手动网上预约太麻烦了,于是写了个程序代替人工预约正文经观察预约系统的预约方式为先登录...
扫描右侧二维码阅读全文
17
2022/03

代手动座位自动预约程序

序言

近段时间不让占座位了,但是手动网上预约太麻烦了,于是写了个程序代替人工预约

正文

经观察预约系统的预约方式为先登录后预约,通过抓包工具获得请求的url的内容。

1. 登录模块

请求的url为:http://xxxxx/api.php/login
请求携带的内容为:账号、密码、验证码,

username: xxxxxxx
password: xxxxx
verify: xxxxx

这个好解决,直接上selenium,验证码模块通过验证码识别进行破解输入,直接登录。

2. 预约模块

通过抓包找到请求的url为:http://xxxxx/api.php/spaces/xxxx/book
请求携带的内容为:

access_token: xxx
userid: xxxx
segment: xxx
type: 1
operateChannel: 2

每次请求的url的倒数第二个参数都不同,经过多次预约发现了其规律座位号 = 请求连接数字-4892 ,对于access_tokenuserid是自动获取的,模拟表单时不必在去获取提交,模拟表单的内容为5个input,access_token和userid的value设置为空,对于segment设置为该间教室的就可(这里就不透露了)type值设为1,operateChannel的值设为2,表单的action设置为对应的url,然后发送请求即可。

代码部分

# -*-coding:utf-8 -*-
# 作者:不懂先生
# 日期: 2022/3/5
import pyautogui
import time
import requests
import smtplib
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from email.header import Header
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from hashlib import md5
#进行图片裁剪
from PIL import Image
#引入动作链
from selenium.webdriver import ActionChains
# 封装识别验证码图片的函数
class Chaojiying_Client(object):
    def __init__(self, username, password, soft_id):
        self.username = username
        password =  password.encode('utf8')
        self.password = md5(password).hexdigest()
        self.soft_id = soft_id
        self.base_params = {
            'user': self.username,
            'pass2': self.password,
            'softid': self.soft_id,
        }
        self.headers = {
            'Connection': 'Keep-Alive',
            'User-Agent': 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)',
        }

    def PostPic(self, im, codetype):
        """
        im: 图片字节
        codetype: 题目类型 参考 http://www.chaojiying.com/price.html
        """
        params = {
            'codetype': codetype,
        }
        params.update(self.base_params)
        files = {'userfile': ('ccc.jpg', im)}
        r = requests.post('xxxx', data=params, files=files, 
        headers=self.headers)
        return r.json()

    def ReportError(self, im_id):
        """
        im_id:报错题目的图片ID
        """
        params = {
            'id': im_id,
        }
        params.update(self.base_params)
        r = requests.post('xxxx', data=params, headers=self.headers)
        return r.json()

s = Service("chromedriver.exe")
bro = webdriver.Chrome(service=s)
bro.maximize_window() #浏览器窗口显示最大化 保证截图完整
bro.get('xxxxx')

login_in = bro.find_element(By.XPATH, '/html/body/div[2]/div[1]/ul/li[4]/a')
login_in.click()
login_in_username = bro.find_element(By.XPATH, '//*[@id="content:login-dialog"]/div/div[1]/input')
login_in_passwd = bro.find_element(By.XPATH, '//*[@id="content:login-dialog"]/div/div[2]/input')
cardid = xxxx
login_in_username.send_keys(cardid)
login_in_passwd.send_keys('xxxx')
time.sleep(2)

bro.save_screenshot('首页截图.png')
code_img_ele = bro.find_element(By.XPATH, '//*[@id="checkpic"]')
location = code_img_ele.location
size = code_img_ele.size
rangle = (int(location['x']),int(location['y'])*1.25,int(location['x']+size['width'])*1.25,int(location['y']+size['height'])*1.25
)
i = Image.open('./首页截图.png')
code_img_name = 'code.png'
frame = i.crop(rangle)
frame.save(code_img_name)
chaojiying = Chaojiying_Client('xxxx', 'xxxxx', 'xxxx')    #用户中心>>软件ID 生成一个替换
im = open('code.png', 'rb').read()#本地图片文件路径 来替换 a.jpg 有时WIN系统须要//
result = chaojiying.PostPic(im, 1004)['pic_str']
print(result)
code_tag = bro.find_element(By.XPATH, '//*[@id="content:login-dialog"]/div/div[3]/input')
code_tag.send_keys(result)
verty = bro.find_element(By.XPATH, '/html/body/div[11]/div/table/tbody/tr[3]/td/div[2]/button[2]')
verty.click()

seatnum = pyautogui.prompt(title="座位预约",text='请输入预选座位:')
predictseatnum = int(seatnum)+4892
predictseatnum = str(predictseatnum)
do = open("xxxx", "w")
print('''
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<title></title>
<meta charset="utf-8">
<meta name="referrer" content="never">
</head>
<body>''',file=do)
print('<form action="xxxxx'+predictseatnum+'/book" method="post" >',file=do)
print('<input type="text" name= "access_token" value="">',file=do)
print('<input type="text" name="userid" value="">',file=do)
print('<input type="text" name="segment" value="xxxx">',file=do)
print('<input type="text" name="type" value="1">',file=do)
print('<input type="text" name="operateChannel" value="2">',file=do)
print('<input type="submit">',file=do)
print('''
</form>
</body>
</html>''',file=do)
do.close()
time.sleep(2)
pyautogui.hotkey('ctrl','n')
pyautogui.typewrite('zwyy.com')
pyautogui.hotkey('enter')
left1, top1, width1, height1 = pyautogui.locateOnScreen('submit.png')
x1, y1 = pyautogui.center((left1, top1, width1, height1))
pyautogui.click(x1,y1)
Last modification:March 28th, 2022 at 07:17 pm

Leave a Comment