It's summer vacation. Are you still worried about clocking in for health? Congratulations, you'll be free to punch in soon. Although there are many relevant codes on the Internet, it doesn't seem so easy to implement. Therefore, I'm going to write specific steps to help most students get rid of the trouble of punching in every day. Next, you don't need to understand the specific details. You just need to follow the steps.
The program mainly simulates sending the request through Python and sends the clock out result through email. First, let's see the effect:
In order to prevent response timeout, I clock in twice a day. The following are the specific steps:
1, Register Tencent cloud
Follow the prompts on this page to register
2, Cloud function found
Then click management console:
Click function service:
New function:
Click Custom to create
Will jump to this page
Set the following timeout:
preservation:
3, Code part
# -*- coding: utf8 -*- import json import re import requests import smtplib from email.mime.text import MIMEText from email.header import Header def send_email(contents): #Configure mailbox host. QQ mailbox can also be used if there is no 163 mailbox #mailhost = 'smtp.qq.com' mailhost = 'smtp.qq.com' mail = smtplib.SMTP() #Connect host through port 25 mail.connect(mailhost,25) #Write your email here sender = '******@qq.com' #SMTP/IMAP authorization code. Open it in personal mailbox. Do not use mailbox password password = '********' #The recipient can be the same as the sender, that is, send an email to yourself receiver = '*******@qq.com' mail.login(sender, password) #Mail content news = contents message = MIMEText(news,'plain','utf-8') #Mail title subject = 'Punch in status:' message['Subject'] = Header(subject,'utf-8') #Trying to catch error try: #If you report an error here, change the host to QQ mailbox mail.sendmail(sender,receiver,message.as_string()) print('Mail sent') except Exception as e: print('Mail sending failed\n' + e) mail.quit() def test_url(): # def main_handler(event, context): #login headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0', 'referer':'https://jksb.v.zzu.edu.cn/vls6sss/zzujksb.dll/first0?fun2=a', 'Content-Type':'application/x-www-form-urlencoded' } form = { "uid": "******", "upw": "******", "smbtn": "Enter the health status reporting platform", "hh28": "750" #Calculated according to the current browser window size } r = requests.post("https://jksb.v.zzu.edu.cn/vls6sss/zzujksb.dll/login",headers=headers,data=form) #response is the ptopid and sid information corresponding to the account password text = r.text.encode(r.encoding).decode(r.apparent_encoding) #Solve the problem of garbled code #first6 matchObj = re.search(r'ptopid=(\w+)\&sid=(\w+)\"',text) ptopid = matchObj.group(1) sid = matchObj.group(2) headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0', 'referer':'https://jksb.v.zzu.edu.cn/vls6sss/zzujksb.dll/login' } r = requests.get("https://jksb. v.zzu. edu. cn/vls6sss/zzujksb. dll/jksb? Ptopid = "+ ptopid +" & sid = "+ Sid +" & fun2 = ") #response contains params corresponding to jksb text = r.text.encode(r.encoding).decode(r.apparent_encoding) #Solve the problem of garbled code #jksb?with_params matchObj = re.search(r'ptopid=(\w+)\&sid=(\w+)\&',text) ptopid = matchObj.group(1) sid = matchObj.group(2) headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0', 'referer':'https://jksb.v.zzu.edu.cn/vls6sss/zzujksb.dll/login' } r = requests.get("https://jksb. v.zzu. edu. cn/vls6sss/zzujksb. dll/jksb? Ptopid = "+ ptopid +" & sid = "+ Sid +" & fun2 = ", headers = headers) #response is the first page of jksb form ptopid1 = ptopid sid1 = sid text = r.text.encode(r.encoding).decode(r.apparent_encoding) #Solve the problem of garbled code #DONE matchObj = re.search(r'name=\"ptopid\" value=\"(\w+)\".+name=\"sid\" value=\"(\w+)\".+',text) ptopid = matchObj.group(1) sid = matchObj.group(2) form = { "day6": "b", "did": "1", "door": "", "men6": "a", "ptopid": ptopid, "sid": sid } headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0', 'Referer': 'https://jksb.v.zzu.edu.cn/vls6sss/zzujksb.dll/jksb?ptopid='+ptopid1+'&sid='+sid1+'&fun2=', 'Content-Type':'application/x-www-form-urlencoded' } r = requests.post("https://jksb.v.zzu.edu.cn/vls6sss/zzujksb.dll/jksb",headers=headers,data=form) #response is the second form of clock in text = r.text.encode(r.encoding).decode(r.apparent_encoding) #Solve the problem of garbled code #DONE matchObj = re.search(r'name=\"ptopid\" value=\"(\w+)\".+name=\"sid\" value=\"(\w+)\"',text) ptopid = matchObj.group(1) sid = matchObj.group(2) form = { "myvs_1": "no", "myvs_2": "no", "myvs_3": "no", "myvs_4": "no", "myvs_5": "no", "myvs_6": "no", "myvs_7": "no", "myvs_8": "no", "myvs_9": "no", "myvs_10": "no", "myvs_11": "no", "myvs_12": "no", "myvs_13a": "41", "myvs_13b": "4101", "myvs_13c": "Henan Province.Zhengzhou City.100 science Avenue", "myvs_14": "no", "myvs_14b": "", "memo22": "[undetermined]", "did": "2", "door": "", "day6": "b", "men6": "a", "sheng6": "", "shi6": "", "fun3": "", "jingdu": "0.0000", "weidu": "0.0000", "ptopid": ptopid, "sid": sid } headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0', 'Referer':'https://jksb.v.zzu.edu.cn/vls6sss/zzujksb.dll/jksb', 'Content-Type':'application/x-www-form-urlencoded' } r = requests.post("https://jksb.v.zzu.edu.cn/vls6sss/zzujksb.dll/jksb",data=form,headers=headers) #response is to complete the clock out page text = r.text.encode(r.encoding).decode(r.apparent_encoding) #Solve the problem of garbled code if("Thank you for reporting your health today!" in text): send_email("Punch in successfully") else: send_email("Clock out failed") def main_handler(event, context): test_url()
Changes required:
Note that you only need to change the ****** in the quotation marks. Both sender and receiver are your mailbox. The password is obtained as follows:
Then paste the authorization code to the password.
uid is your student ID and upw is your password (make sure these two are correct first)
For code ideas, please refer to: https://blog.csdn.net/MonkeyWang98
Click deploy:
Then click test:
This means that there is no problem, but if you punch in today, the email you send may be the content of punch in failure.
In addition, if the test fails, the response may timeout due to your unstable network. Click again.
4, Set scheduled tasks
The representative clocks in at 12:15 every day
You can set several more to prevent clock out failure caused by network instability
So far, it's over. You don't have to stay up late and punch in early during the holiday. Yeah.