1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
import time import requests import smtplib from email.mime.text import MIMEText from email.header import Header
from bs4 import BeautifulSoup
while 1: loginurl = 'http://stu88.ntust.edu.tw/inboundchina/stu/login.do' homeurl = "http://stu88.ntust.edu.tw/inboundchina/stu/review.result"
headers = { "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1 Safari/605.1.15", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Encoding": "gzip, deflate", "Host": 'stu88.ntust.edu.tw', "Accept-Language": 'zh-cn', "Content-Type": 'application/x-www-form-urlencoded', 'Referer': 'http://stu88.ntust.edu.tw/inboundchina/stu', "Upgrade-Insecure-Requests": "1", "Origin": 'http://jwk.lzu.edu.cn', "DNT": '1', "Connection": 'keep-alive'
}
session = requests.Session()
payload = { 'email': '[email protected]', 'password': '*******', 'captcha': '' }
def (sub, text): mail_host = "smtp.lzu.edu.cn" mail_user = "*****" mail_pass = "*****"
sender = '[email protected]' receivers = ','.join(['[email protected]']) message = MIMEText(text, 'plain', 'utf-8') message['From'] = Header("自动发送", 'utf-8') message['To'] = Header("Rankin", 'utf-8')
subject = sub message['Subject'] = Header(subject, 'utf-8') try: smtpObj = smtplib.SMTP() smtpObj.connect(mail_host, 25) smtpObj.login(mail_user, mail_pass) smtpObj.sendmail(sender, receivers, message.as_string()) print("邮件发送成功") except smtplib.SMTPException: print("send mail error!")
try: response_login = session.post(loginurl, headers=headers, data=payload) response_home = session.get(homeurl, headers=headers)
except: print("login error!") result = BeautifulSoup(response_home.text, "html.parser") result = result.find(class_="alert alert-info") print(time.strftime("%a %b %d %H:%M:%S %Y", time.localtime()) + " " + result.span.string)
if result.span.string != 'Pass the first stage': send_mail("台科大信息", result.span.string)
time.sleep(600)
|
近期评论