Because the school has to clock in the temperature every day , Filling the body temperature also limits the time period ,0|==|_, So the top of the hour py coordination linux Of crontab, Realize automatic clock in ;
1, Caught analysis
It is found that automatic clock in requires login , Just type in your account and password ;
Grab the package analysis on the login page and find that post How to submit data , also cookie The field carries the account number ,JSESSIONID Etc :
After successful login, three temperature fields are found , And check the time of filling in the body temperature :
Click Submit button , Grab the bag again to analyze :
It is found that the packet contains the same... As the login packet cookie Information , And take post Mode submission json Formatted data , The data contains three main body temperature data morTem,noonTem,eveTem and Time of submission of the report reporttime;
If the packet is correct , After successful submission, return 200, And prompt that the modification is successful :
Code implementation logic :
1, Just log in to cookie Value and in the logged in packet cookie Value consistent , You can go to py The login step is omitted from the code ;
2, Three body temperature variables correspond to three time periods , Use linux Of crontab Set three scheduled tasks to achieve ;
3,reporttime Fill in the temperature date for the day , year - month - Japan , Use py As a function of time ;
The implementation code is as follows ( For reference only py Use ):
#coding=utf-8
import requests
import json
import random
import time
# ==== cookie Raw data ; Global variables ====
cookie = [
"studentCode=11111( account number ); IDNo=1( password )",
"studentCode=22222; IDNo=3",
"studentCode=33333; IDNo=2"
]
studentCode = ''
IDNo = ''
JSESSIONID = 'djfasjfoijaoifjisajfirs'
# ==== Simple data processing ; Withdrawal account , password ====
def get_data(cookie):
global studentCode,IDNo
cookie = cookie.split(';')
studentCode = cookie[0].split('=')[1]
IDNo = cookie[1].split('=')[1]
#JSESSIONID = cookie[2].split('=')[1]
#print(studentCode,IDNo,JSESSIONID)
#=== Test login : This module can be omitted ===
def login():
url = " land URL"
headers = {
"Host": "www.xxx.com",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:87.0) Gecko/20100101 Firefox/87.0",
"Accept": "*/*",
"Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
"Accept-Encoding": "gzip, deflate",
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"X-Requested-With": "XMLHttpRequest",
"Content-Length": "40",
"Origin": "https://www.xxx.com",
"Connection": "close",
"Referer": "https://www.xxx.com/xxx/xxx",
"cookie": "studentCode=1111; IDNo=1; JSESSIONID=adljasijfdoijasfoi"
}
data = "studentCode=111&IDNo=1"
response = requests.post(url,data=data,headers=headers)
print(response.text)
#login()
#=== Fill in the temperature ====
def inp(studentCode,IDNo,JSESSIONID):
# Fill in the temperature URL
url2 = "https://www.xxx.com/xxx"
# http Packet header information , contain cookie Login free steps
headers = {
"Host": "www.xxx.com",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:87.0) Gecko/20100101 Firefox/87.0",
"Accept": "*/*",
"Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
"Accept-Encoding": "gzip, deflate",
"Content-Type": "application/json",
"X-Requested-With": "XMLHttpRequest",
"Content-Length": "499",
"Origin": "https://www.xxx.com",
"Connection": "close",
"Referer": "https://www.xxx.com/xxx",
"cookie": "studentCode={0}; IDNo={1}; JSESSIONID={2}".format(studentCode,IDNo,JSESSIONID)
}
# === Randomly generated body temperature ====
e = 36
d = int(random.uniform(0.4,0.7) * 10) /10
#print(a,b,c)
# === Get the time of the day ====
times = time.strftime("%Y-%m-%d",time.localtime())
print(times)
# http Packet request body , Fill in the temperature
data = {
"studentCode":"{}".format(studentCode),
"classNo":"xxx",
"departmentCode":"02",
"depName":"xxx",
"acaID":"1",
"bodystatus":" normal ",
"animalHeat": None,
"address":"xxx School ",
"isContactHubeiBack":"0",
"isContactPatient":"0",
"othercase":"",
"reporttime":"{}".format(times),
"noonTem":"%s"%str(e+d),
"illsymptom": None,
"quarantine": None,
"quarantinePlace": None,
"outStartTime": None,
"outEndTime": None,
"vehicle": None,
"trainNumAndseatNum": None
}
# send out post request , The body of the request is json Format data
response = requests.post(url2,headers=headers,json=data)
# Returns the data content encoding
response.encoding = response.apparent_encoding
# printout
print(response.text)
# Batch punch in
for i in cookie:
get_data(i)
#print(studentCode,IDNo,JSESSIONID)
inp(studentCode,IDNo,JSESSIONID)
linux crontab Set timing task :
crontab -l -u root【 Or user name 】 # Lists scheduled tasks for the specified user
crontab -e # Set the scheduled task of the current user
Remember to restart every time the scheduled task is set crontab
systemctl restart cron
# The corresponding meaning of each parameter
# .---------------- branch (0 - 59)
# | .------------- when (0 - 23)
# | | .---------- God (1 - 31)
# | | | .------- month (1-12)
# | | | | .---- Zhou 1-7
# | | | | |
* * * * * Commands to perform tasks /command
take py Three copies of the code , Change the names of three body temperature variables , Set up three scheduled tasks , Use py3 Can run ( Be careful linux Time zone problem ,date Check the time zone , The general time zone is CST);