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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
| import os import re from lxml import etree import requests import sys from bs4 import BeautifulSoup import smtplib from email.mime.text import MIMEText import threading import time from qcloudsms\_py import SmsSingleSender from qcloudsms\_py.httpclient import HTTPError
s = requests.session() url = "http://jwxt.i.cqut.edu.cn" response = s.get(url)
newUrl = response.url
selector = etree.HTML(response.content) \_\_VIEWSTATE = selector.xpath('//*\[@id="form1"\]/input/@value')\[0\]
imgUrl = newUrl.replace('Default2.aspx','CheckCode.aspx') imgresponse = s.get(imgUrl, stream=True) image = imgresponse.content
if os.path.exists(r'f://yanzheng.jpg'): os.remove(r'f://yanzheng.jpg') with open(r'f://yanzheng.jpg','wb')as f: f.write(image) f.close() os.startfile(r'f:yanzheng.jpg')
code = input("输入弹出的验证码: ")
data={ '\_\_VIEWSTATE':\_\_VIEWSTATE, 'txtUserName':'学号', 'TextBox2':'密码', 'txtSecretCode':code, 'RadioButtonList1':'%D1%A7%C9%FA', 'Button1':"", 'lbLanguage':'', 'hidPdrs':'', 'hidsc':'', }
headers={ 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36' }
response = s.post(newUrl,data=data,headers=headers)
ata1={ 'xh':'11503080431', 'xm':'%C0%EE%C7%EC%CD%FA', 'gnmkdm':'N121607' }
headers1={ 'Referer':response.url , 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36' }
response = s.get(newUrl.replace('Default2.aspx','xscjcx\_dq.aspx?xh=11503080431&xm=%C0%EE%C7%EC%CD%FA&gnmkdm=N121607'),data=data1,headers=headers1) content1 = response.content.decode('gb2312')
selector = etree.HTML(content1) \_hhh = selector.xpath('//*\[@id="Form1"\]/input/@value')\[2\]
data2={ '\_\_EVENTTARGET':'', '\_\_EVENTARGUMENT':'', '\_\_VIEWSTATE':\_hhh, 'ddlxn':'2017-2018', 'ddlxq':'2', 'btnCx':'+%B2%E9++%D1%AF+' }
def sendMail(grade): \_user = "302657615@qq.com" \_pwd = "授权码" \_to = "302657615@qq.com" msg = MIMEText("出分啦!!考了 " + grade) msg\["Subject"\] = "出分啦!!考了 " + grade msg\["From"\] = "wangyezaici" msg\["To"\] = \_to s = smtplib.SMTP\_SSL("smtp.qq.com", 465) s.login(\_user, \_pwd) s.sendmail(\_user, \_to, msg.as\_string()) s.quit() def sendSms(a, b): appid = ; appkey = ""; phone\_numbers = \[""\]; template\_id = ; ssender = SmsSingleSender(appid, appkey) params = \[a, b\] try: result = ssender.send\_with\_param(86, phone\_numbers\[0\], template\_id, params) except HTTPError as e: print(e) except Exception as e: print(e) print(result) def fun\_timer(): response = s.post(newUrl.replace('Default2.aspx','xscjcx\_dq.aspx?xh=11503080431&xm=%C0%EE%C7%EC%CD%FA&gnmkdm=N121607'),data=data2,headers=headers1) content2 = response.content.decode('gb2312') soup = BeautifulSoup(content2, 'lxml') print(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))) tables = soup.findAll('table') tab = tables\[1\] trs = tab.findAll('tr') del trs\[0\] for tr in trs: tds = tr.findAll('td') if tds\[3\].string.find("编译") != -1: print(tds\[3\].string + "考了" + tds\[11\].string) sendMail(tds\[11\].string) sendSms(tds\[3\].string, tds\[11\].string) sys.exit() global timer timer = threading.Timer(180, fun\_timer) timer.start() timer = threading.Timer(1, fun_timer) timer.start()
|