要查46级成绩,我们可以到www.99sushe.com查询,它的那些类型选项是为了验证准考证号是否正确,都是在js中完成。换句话说,如果我们直接向服务器发数据,可以忽略这个选项而直接发送准考证和名字前两个汉字。
对于华工的学生,可以在http://222.16.33.245:888/cet.asp这里通过输入自己的学号和名字,查询到自己的准考证号。当我们点击了查询,浏览器会向http://222.16.33.245:888/cetresult.asp这里发送数据。我们可以打包发到那里。这里需要教育网访问。
# -*- coding:utf-8 -*- # 从华工网上获取四六级准考证号 # 作者:华亮 from Queue import Empty from Queue import Queue from sys import exit from urllib import urlencode import re import threading import urllib import urllib2 ''' kssj:111 loginName:%C2%DE%BC%CE%B7%C9 (unable to decode value) loginPass:200930635086 ''' def connect(username, userid): loginData = {'kssj':'111', 'loginName':username.decode('utf-8').encode('gb2312'), 'loginPass':userid} postData = urlencode(loginData) req = urllib2.Request('http://222.16.33.245:888/cetresult.asp', postData) cookieFile = urllib2.HTTPCookieProcessor() opener = urllib2.build_opener(cookieFile) result = opener.open(req) return re.findall(r'<td width="296">(\d{15})</td>', result.read()) def GetScore(id, username): loginData = {'id':id, 'name':username.decode("utf-8").encode("gbk") } postData = urlencode(loginData) print postData req = urllib2.Request('http://cet.99sushe.com/s') req.add_header("Origin", "http://cet.99sushe.com") req.add_header("Referer", "http://cet.99sushe.com") req.add_data(postData) cookieFile = urllib2.HTTPCookieProcessor() opener = urllib2.build_opener(cookieFile) result = opener.open(req) return result.read() def main(): file = open('user.txt') file2 = open('id.txt', 'w') userinfo = [] for line in file: id, name = line.split()[0], line.split()[1] userinfo.append((id, name)) id_nameList = [] for id, name in userinfo: try: eid = connect(name, id)[ 0 ] print eid, print name file2.write(eid + ' ') file2.write(name) file2.write('\n') #id_nameList.append((eid, name)) #print GetScore(id, name) except: pass file2.close() for id, name in id_nameList: print id, print name #GetScore(id, name) if __name__ == '__main__': main()
我们可以切换到电信网。运行下面的代码向99sushe查询四六级成绩。
# -*- coding:utf-8 -*- # 从99sushe获取四六级成绩 # 作者:华亮 from HTMLParser import HTMLParser from Queue import Empty from Queue import Queue from re import match from sys import exit from urllib import urlencode import os import re import socket import threading import time import urllib import urllib2 import shelve def GetScore(id, username): loginData = {'id':id, 'name':username.decode("utf-8").encode("gbk") } postData = urlencode(loginData) #print postData req = urllib2.Request('http://cet.99sushe.com/s') req.add_header("Origin", "http://cet.99sushe.com") req.add_header("Referer", "http://cet.99sushe.com") req.add_data(postData) cookieFile = urllib2.HTTPCookieProcessor() opener = urllib2.build_opener(cookieFile) result = opener.open(req) return result.read() ''' 您的成绩总分:387 听力:144 阅读:140 综合:39 写作:64 ''' '144,140,39,64,387,华南理工大学,XXX,0' keyword = ['听力:', '阅读:', '综合:', '写作:', '您的成绩总分:', '学校:', '姓名:', 'End-'] def main(): file = open('id.txt') outfile = open('score.txt', 'w') userinfo = [] for line in file: id, name = line.split()[0], line.split()[1] userinfo.append((id, name)) for id, name in userinfo: i = 0 for item in GetScore(id, name[0:6]).decode('gbk').encode('utf-8').split(','): print keyword[i], print item outfile.write(keyword[i] + ' ') outfile.write(item + '\r\n') i += 1 print outfile.write('\r\n') outfile.close() if __name__ == '__main__': main()