import urllib2 import urllib import threading import time import json import smtplib import gzip import StringIO from email.mime.text import MIMEText from email.header import Header
cookie='JSESSIONID=D5B7900FBCE661659978464309BD23D1; acw_tc=2760824b15502052244788631e101590a210f068338831246151b55dcc5577; JSESSIONID=5BB2C7ADAFD3F24E7179F7E0571B3606; _ga=GA1.4.129029864.1550205225; _gid=GA1.4.1924511835.1550205225' mail_host = "smtp.163.com" mail_user = "********@163.com" mail_pass = "*********"
sender = '*********@163.com' receivers = ['********@163.com']
def fetch2(url,post): headers = {'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Host': 'yz.chsi.com.cn', 'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2', 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36', 'Connection': 'keep-alive', 'Accept-Encoding': 'gzip,deflate', 'Cookie': cookie, 'Referer': 'https://yz.chsi.com.cn/apply/cjcx/', 'Pragma': 'no-cache', 'Upgrade-Insecure-Requests': '1', 'Content-Type': 'application/x-www-form-urlencoded', 'Cache-Control':'no-cache' } data = urllib.urlencode(post) req = urllib2.Request(url, data,headers) response = urllib2.urlopen(req) page_source = response.read() return page_source
def mainfunc(): url='https://yz.chsi.com.cn/apply/code/cjcxdw.do?ssdm=11&ts='+str(int(round(time.time() * 1000))) headers = {'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Host': 'yz.chsi.com.cn', 'Accept-Language': 'zh-CN,zh;q=0.9', 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36', 'Connection': 'keep-alive', 'Accept-Encoding': 'gzip, deflate, br', 'Cookie': cookie, 'Referer': 'https://yz.chsi.com.cn/apply/cjcx/', 'Pragma': 'no-cache', 'Upgrade-Insecure-Requests': '1', 'Content-Type': 'application/x-www-form-urlencoded', 'Cache-Control': 'no-cache' }
print("开始查询!") try: req = urllib2.Request(url, None, headers) response = urllib2.urlopen(req) res = response.read() jsonobj=json.loads(res) schoolist=jsonobj['dms'] flag=0 schoolcode=10050 global timer for i in schoolist: schoolname=i['mc'] if schoolname.encode('utf-8') == '北京航空航天大学': flag=1 schoolcode=i['dm'] if(flag==1): url2 = 'https://yz.chsi.com.cn/apply/cjcx/cjcx.do' post = {'xm': '张三', 'zjhm':'身份证号', 'ksbh': '', 'bkdwdm': schoolcode, 'checkcode': ''} re = fetch2(url2, post) re = StringIO.StringIO(re) gz = gzip.GzipFile(fileobj=re) re = gz.read() gz.close() message = MIMEText(re, _subtype='html',_charset='utf-8') message['From'] = "lufer<*********@163.com>" message['To'] = "Receiver" subject = '出分了!' message['Subject'] = Header(subject, 'utf-8') smtpObj = smtplib.SMTP() smtpObj.connect(mail_host, 25) smtpObj.ehlo() smtpObj.starttls() smtpObj.login(mail_user, mail_pass) smtpObj.sendmail(sender, receivers, message.as_string()) print "已查询到成绩j,邮件发送成功" smtpObj.quit() timer.cancel() return else: print("没有查询到制定学校") except Exception as e: print('发生了异常:', e) timer = threading.Timer(60, mainfunc) timer.start()
mainfunc()
|
文章评论