请先看此篇文章,讲的很清楚。GitHub Action自动完成华工疫情打卡、网站自动签到 看懂后,直接使用代码即可。 python代码:此代码参考自体温自动填写,修改而成
import requests as r
from lxml import etree
import time
from time import sleep
a, b, c, d, e, f, z = '', '', '', '', '', '', ''
timetamp = time.mktime(time.localtime())
timetamp = int(timetamp)
y=''
url = "http://xscfw.hebust.edu.cn/survey/ajaxLogin"
url2 = "http://xscfw.hebust.edu.cn/survey/index"
url3 = f"http://xscfw.hebust.edu.cn/survey/surveySave?timestamp={timetamp}"
param = {
"stuNum": "",
"pwd": "",
"vcode": "",
}
header = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.62"
}
try:
response = r.post(url=url, params=param, headers=header)
sleep(20)
cookiesJAR = response.cookies
cookies = cookiesJAR.get_dict()
res = r.get(url=url2, headers=header, cookies=cookies, params=param)
b = "正在登录,即学校网页可以正常进入"
except:
b = "登录失败,即学校网页无法进入"
try:
res.encoding = 'uft-8'
html = etree.HTML(res.text)
content = html.xpath('/html/body/ul/li[1]/div/span/text()')
y=content[0]
c = "获取填报表单成功,即登录成功"
except:
c = "获取填报表单失败,即登录失败"
try:
url4 = 'http://xscfw.hebust.edu.cn/survey/index.action'
rek = r.get(url=url4, cookies=cookies, headers=header)
rek.encoding = 'utf-8'
html3 = etree.HTML(rek.text)
sid = html3.xpath('/html/body/ul/li[1]/@sid')[0]
d = "获取当前日期要填的文档的sid成功"
except:
d = "获取当前日期要填的文档的sid失败"
try:
url5 = f'http://xscfw.hebust.edu.cn/survey/surveyEdit?id={sid}'
rej = r.get(url=url5, cookies=cookies, headers=header)
sleep(5)
rej.encoding = 'utf-8'
html2 = etree.HTML(rej.text)
stuId = html2.xpath('//*[@id="surveyForm"]/input[2]/@value')[0]
qid = html2.xpath('//*[@id="surveyForm"]/input[3]/@value')[0]
e = "获取stuId qid 成功"
except:
e = "获取stuId qid 失败"
try:
data = {
"id": sid,
"stuId": stuId,
"qid": qid,
"location": '',
"c0": "不超过37.3℃,正常",
"c1": '36.5',
"c3": "不超过37.3℃,正常",
"c4": '36.5',
"c6": "健康",
}
f = "获取信息成功"
except:
f = "获取信息有误"
if y == '已完成':
z = '早已完成填报,无需填报'
elif y == '未完成':
try:
timetamp = time.mktime(time.localtime())
timetamp = int(timetamp)
rep = r.post(url=url3, params=data, headers=header, cookies=cookies)
a = "填报成功"
except:
a = "填报出错"
else:
z = "填写时间未到,或填写失败"
file = open("mydata.html", 'w+', encoding='UTF-8')
file.write(b + '*****' + c + '*****' + d + '*****' + e + '*****' + f + '*****' + z + '*****' + a)
file.close()
yml代码:
name: tiwentianbao
on:
workflow_dispatch:
schedule:
- cron: '10 2,3 * * *'
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- run: pip install -r ./r.txt
- run: python ./python.py
- name: 'Send mail'
uses: dawidd6/action-send-mail@master
with:
server_address: smtp.163.com
server_port: 465
username: ${{ secrets.EMAILNAME }}
password: ${{ secrets.EMAILPOP }}
subject: 每日体温填报
body: file://mydata.html
to: 0000000@qq.com
from: GitHub Actions
content_type: text/html
依赖库txt文件:
requests
lxml
邮件效果:
|