如果写代码是为了干坏事,那将动力无穷。
具体的可以看看 技术参考链接里大佬的具体实现思路
def AutoSignIn(user_root,user_password):
root = user_root
password = user_password
url = 'http://my.hhu.edu.cn/login.portal'
chromedriver_path = "C:/Program Files (x86)/Google/Chrome/Application/chromedriver.exe"
driver = webdriver.Chrome(chromedriver_path)
driver.get(url)
driver.find_element_by_xpath('//*[@id="username"]').send_keys(root)
driver.find_element_by_xpath('//*[@id="password"]').send_keys(password)
driver.find_element_by_xpath('//*[@id="changeBack"]/tbody/tr/td[2]/table[1]/tbody/tr[2]/td/div/input[1]').click()
sleep(5);
form = 'http://form.hhu.edu.cn/pdc/form/list'
driver.get(form)
sleep(5);
driver.find_element_by_xpath('/html/body/div[1]/div[4]/div/section/section/div/a/div[2]').click()
sleep(5);
driver.find_element_by_xpath('//*[@id="saveBtn"]').click()
sleep(5);
def sendEmail(reciver):
# 发件方
from_addr = '[email protected]'
password = 'yours' # 授权码的获取方式可以百度
# 收件方
to_addr = reciver
# 服务器
smtp_server = 'smtp.qq.com'
#获取时间
i = datetime.datetime.now()
#邮件内容
content = 'DedSec 已经帮你在' + str(i) + ',这个时间完成了你烦人的河海大学健康打卡!##请勿回复##'
# 邮箱正文内容,第一个参数为内容,第二个参数为格式(plain 为纯文本),第三个参数为编码
msg = MIMEText(content, 'plain', 'utf-8')
# 邮件头信息
msg['From'] = Header(from_addr)
msg['To'] = Header(to_addr)
msg['Subject'] = Header('DedSec')
# 开启发信服务,这里使用的是加密传输
server = smtplib.SMTP_SSL(smtp_server)
server.connect(smtp_server, 465)
# 登录发信邮箱
server.login(from_addr, password)
# 发送邮件
server.sendmail(from_addr, to_addr, msg.as_string())
# 关闭服务器
server.quit()
class user_info:
username = ''
password = ''
email = ''
def __init__(self,userName,passWord,Email):
self.username = userName
self.password = passWord
self.email = Email
from selenium import webdriver
from time import sleep
# smtplib 用于邮件的发信动作
import smtplib
# email 用于构建邮件内容
from email.mime.text import MIMEText
# 用于构建邮件头
from email.header import Header
#日期与时间
import datetime
import time
class user_info:
username = ''
password = ''
email = ''
def __init__(self,userName,passWord,Email):
self.username = userName
self.password = passWord
self.email = Email
def AutoSignIn(user_root,user_password):
root = user_root
password = user_password
url = 'http://my.hhu.edu.cn/login.portal'
chromedriver_path = "C:/Program Files (x86)/Google/Chrome/Application/chromedriver.exe"
driver = webdriver.Chrome(chromedriver_path)
driver.get(url)
driver.find_element_by_xpath('//*[@id="username"]').send_keys(root)
driver.find_element_by_xpath('//*[@id="password"]').send_keys(password)
driver.find_element_by_xpath('//*[@id="changeBack"]/tbody/tr/td[2]/table[1]/tbody/tr[2]/td/div/input[1]').click()
sleep(5);
form = 'http://form.hhu.edu.cn/pdc/form/list'
driver.get(form)
sleep(5);
driver.find_element_by_xpath('/html/body/div[1]/div[4]/div/section/section/div/a/div[2]').click()
sleep(5);
driver.find_element_by_xpath('//*[@id="saveBtn"]').click()
sleep(5);
def sendEmail(reciver):
# 发件方
from_addr = '[email protected]'
password = 'yours'
# 收件方
to_addr = reciver
# 服务器
smtp_server = 'smtp.qq.com'
#获取时间
i = datetime.datetime.now()
#邮件内容
content = 'DedSec 已经帮你在' + str(i) + ',这个时间完成了你烦人的河海大学健康打卡!##请勿回复##'
# 邮箱正文内容,第一个参数为内容,第二个参数为格式(plain 为纯文本),第三个参数为编码
msg = MIMEText(content, 'plain', 'utf-8')
# 邮件头信息
msg['From'] = Header(from_addr)
msg['To'] = Header(to_addr)
msg['Subject'] = Header('DedSec')
# 开启发信服务,这里使用的是加密传输
server = smtplib.SMTP_SSL(smtp_server)
server.connect(smtp_server, 465)
# 登录发信邮箱
server.login(from_addr, password)
# 发送邮件
server.sendmail(from_addr, to_addr, msg.as_string())
# 关闭服务器
server.quit()
if __name__ == '__main__':
#刘生伟
user = user_info('username','password','[email protected]')
userList = [user];
for i in range (len(userList)):
AutoSignIn(userList[i].username,userList[i].password)
sendEmail(userList[i].email)
print("打卡完毕,邮件发送完毕")
sleep(5)
print("全部完毕")
因为适用性比较低,数据直接存储在代码里,如果可以接收大用户量,可以考虑使用数据库。