一、效果
二、代码
有部分我更改了,账号密码改成你自己的,按照提示自己更改隐私内容。
# selenium 自动化测试库
# 模块安装pip install selenium smtplib ddddocr
from selenium import webdriver
import random
import time
from selenium.webdriver.chrome.options import Options
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import ddddocr
#你可以在这个字典里填写多个人的账号和密码
dir = {'账号':'密码'}
succes = 0
falled = 0
for i,j in dir.items():
# uniform(a,b)生成a到b之间的浮点数,要求每次随机生成温度在36到37之间
result = str(random.uniform(36,37))[0:4]
try:
# 打开浏览器
chrome_options = Options()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--headless')
brower = webdriver.Chrome(r'D:\360安全浏览器下载\chromedriver.exe',chrome_options=chrome_options)
brower.get('https://web-vpn.sues.edu.cn/https/77726476706e69737468656265737421f3f652d234256d43300d8db9d6562d/cas/login?service=https%3A%2F%2Fweb-vpn.sues.edu.cn%2Flogin%3Fcas_login%3Dtrue')
# ****** 替换成自己账号
time.sleep(1)
brower.find_element_by_id('username').send_keys(i)
# ****** 替换成自己密码
time.sleep(1)
brower.find_element_by_id('password').send_keys(j)
# authcode
time.sleep(3)
brower.find_element_by_class_name('codeImg').screenshot('ss.png')
ocr = ddddocr.DdddOcr()
with open('ss.png', 'rb') as f:
img_bytes = f.read()
res = ocr.classification(img_bytes)
print(res)
brower.find_element_by_id('authcode').send_keys(res)
# 模拟登录
brower.find_element_by_id('passbutton').click()
time.sleep(1)
# 第二步:模拟程序自动录入体温提交
# 发送网络请求
brower.get('https://web-vpn.sues.edu.cn/https/77726476706e69737468656265737421e7f85397213c6747301b9ca98b1b26312700d3d1/default/work/shgcd/jkxxcj/jkxxcj.jsp')
# 模拟鼠标滚动到页面底部
time.sleep(1)
brower.execute_script("var action=document.documentElement.scrollTop=2000")
# 首先定位到input,清空输入框信息
brower.find_element_by_xpath('//div[@class="form-td col-sm-6 col-xs-12"]').click()
brower.find_element_by_xpath('//input[@placeholder="范围35.0-45.0"][@class="form-control"][@name="tw"]').clear()
# 将程序每次随机生成的体温,
time.sleep(2)
brower.find_element_by_xpath('//input[@placeholder="范围35.0-45.0"][@class="form-control"][@name="tw"]').send_keys(result)
# 程序模拟点击提交
brower.find_element_by_id('post').click()
brower.find_element_by_xpath('//a[@class="layui-layer-btn0"]').click()
succes += 1
time.sleep(1)
brower.quit()
except:
falled += 1
# 1秒之后关闭窗口
time.sleep(1)
jieguo="\n成功:%d 失败:%d"%(succes,falled)
print(jieguo)
def send_email(msg_from, passwd, msg_to, text_content):
msg = MIMEMultipart()
subject = "计算机2班填体温结果" # 主题
text = MIMEText(text_content)
msg.attach(text)
msg['Subject'] = subject
msg['From'] = msg_from
msg['To'] = msg_to
try:
s = smtplib.SMTP_SSL("smtp.qq.com", 465)
s.login(msg_from, passwd)
s.sendmail(msg_from, msg_to, msg.as_string())
print("发送成功")
except smtplib.SMTPException as e:
print("发送失败")
finally:
s.quit()
msg_from = '2835809579@qq.com' # 发送方邮箱
passwd = '授权码' # 如何得到授权码?请查看我的这一篇博客:请参考https://chuanchuan.blog.csdn.net/article/details/121243675
msg_to = '2835809579@qq.com' # 收件人邮箱
text_content = jieguo # 发送的邮件内容
send_email(msg_from,passwd,msg_to,text_content)
github地址:https://github.com/89461561511656/tem
声明
如果你有发现自己不适,或者发高烧,请主动去医务室就诊,本代码仅懒人使用,一切后果概不负责。
本代码仅工程大的同学使用,其它学校的同学可以模仿此类进行代码编写。
如有问题可是私聊我:
Q:2835809579