某校健康打卡自動簽到
阿新 • • 發佈:2021-02-02
設計思路
一、抓包
這裡是抓取了大學的健康簽到網址,並進行分析
登入介面
簽到介面
這裡也是對簽到內容進行一次模擬,然後抓包,取得相應資料
二、實現思路
1.實現登入
由於這個簽到是在該校官網,所以得先去測試下登入介面,發現登陸後會返回token,並對之後的資料進行請求,這裡便選擇使用Session來實現會話保持(由於是幫朋友寫的,前面沒有學號和密碼,就只能隨便資料賬號密碼進行抓包測試,發現密碼利用了 md5編碼
程式碼實現:
def login():
header = {
"User-Agent": "Mozilla/5.0"
}
data = {
"username": '學號',
"password": hashlib.md5(b'密碼').hexdigest()
}
loginUrl = 'http://xgpt.hbmu.edu.cn/website/login'
req = session.post(loginUrl, headers= header, data=data)
2.實現簽到
這裡的data資料是通過之前模擬填寫的資料抓包得到的,具體內容識實際情況而定
def origin(req):
t = int(round(time.time()*1000))
postURL= f'http://xgpt.hbmu.edu.cn/content/student/temp/zzdk?_t_s_={t}'
header = {
"User-Agent":'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1'
}
data = {
'dkdz':'湖北省宜昌市西陵區列電路6 -、8 -、10號',
"dkly":'baidu',
"dkd":"湖北省宜昌市",
"jzdValue":"420000, 420500, 420581",
"jzdSheng.dm":420000,
"jzdShi.dm":420500,
"jzdXian.dm":420581,
"jzdDz":"湖北省宜都市*******",
"jzdDz2":"湖北省宜都市*****",
"lxdh":手機號,
"sflx":1,
"twM.dm":"01",
"tw1":"[35.0~37.2]正常",
"yczk.dm":"01",
"yczk1":"無症狀",
"brStzk.dm":"01",
"brStzk1":"身體健康、無異常",
"brJccry.dm":"01",
"brJccry1":"未接觸傳染源",
"jrStzk.dm":"01",
"jrStzk1":"身體健康、無異常",
"jrJccry.dm":"01",
"jrJccry1":"未接觸傳染源",
"bz":"",
"operationType":"",
"Create":"",
"dm":""
}
r = session.post(postURL ,headers = header ,data=data)
3.利用zmail進行郵件的傳送
關於zmail郵件傳送,主要就是需要一個傳送者郵箱,並開啟pop3等,網易配置可參考我的另一篇文章監測小說更新狀態併發送郵箱
zmail程式碼如下:
import zmail
def send_email(text):
# 你的郵件內容
mail_content = {
'subject': 'Success!', # 隨便填寫
'content_text': text, # 隨便填寫
}
server = zmail.server('傳送者郵箱', '傳送者郵箱客戶端授權碼')
# 傳送郵件
server.send_mail('接收者郵箱', mail_content)
4.設定定時運
if __name__ == '__main__':
while True:
current_time = datetime.now().hour
if (current_time == 7 ):
login()
time.sleep(3600*24)
5.將程式碼上傳到伺服器,並後臺執行
三、詳細程式碼
import requests
import hashlib
import time
import logging
import os.path
import zmail
from datetime import datetime
session = requests.Session()
def login():
header = {
"User-Agent": "Mozilla/5.0"
}
data = {
"username": '學號',
"password": hashlib.md5(b'密碼').hexdigest()
}
loginUrl = 'http://xgpt.hbmu.edu.cn/website/login'
req = session.post(loginUrl, headers=header, data=data)
origin(req)
def origin(req):
t = int(round(time.time()*1000))
postURL= f'http://xgpt.hbmu.edu.cn/content/student/temp/zzdk?_t_s_={t}'
header = {
"User-Agent":'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1'
}
data = {
'dkdz':'湖北省宜昌市西陵區列電路6 -、8 -、10號',
"dkly":'baidu',
"dkd":"湖北省宜昌市",
"jzdValue":"420000, 420500, 420581",
"jzdSheng.dm":420000,
"jzdShi.dm":420500,
"jzdXian.dm":420581,
"jzdDz":"湖北省宜都市*******",
"jzdDz2":"湖北省宜都市*****",
"lxdh":"手機號",
"sflx":1,
"twM.dm":"01",
"tw1":"[35.0~37.2]正常",
"yczk.dm":"01",
"yczk1":"無症狀",
"brStzk.dm":"01",
"brStzk1":"身體健康、無異常",
"brJccry.dm":"01",
"brJccry1":"未接觸傳染源",
"jrStzk.dm":"01",
"jrStzk1":"身體健康、無異常",
"jrJccry.dm":"01",
"jrJccry1":"未接觸傳染源",
"bz":"",
"operationType":"",
"Create":"",
"dm":""
}
r = session.post(postURL ,headers = header ,data=data)
send_email(r.text)
def send_email(text):
# 你的郵件內容
mail_content = {
'subject': 'Success!', # 隨便填寫
'content_text': text, # 隨便填寫
}
server = zmail.server('傳送者郵箱', '傳送者郵箱客戶端授權碼')
# 傳送郵件
server.send_mail('接收者郵箱', mail_content)
if __name__ == '__main__':
while True:
current_time = datetime.now().hour
if (current_time == 7 ):
login()
time.sleep(3600*24)