import httplib
import sys
import time
id = "20101974"
password = "*********"
msg ="loginType=2&username=%s&name=%s&jwydm=&password=%s&pswd=%s&jwypswd=&image.x=30&image.y=5"% (id, id, password, password)
def get(s):
out=''
state =False
for ch ins:
if ch == '<':
state = True
continue
elif ch == '>':
state = False
continue
if state == True:
continue
else:
out += ch
returnout
def getgpa(x):
ifx<60:
return 0;
else:
return 1.0+(x-60)/5*0.5
def exit():
sys.exit()
def score(s):
s =s.decode('gbk')
pos =1
end =0
l=[]
whilepos>0:
t = []
for i in range(0, 9):
pos = s.find("VALIGN="center">", pos)
if pos>0:
end =s.find("r="".join(s[pos+16:end].split())
t.append(r)
pos = end
l.append(t)
for x inl:
out = ""
if x != []:
print "%-4s%sn%-4st%-4s" %(x[0]+'.', x[2], get(x[4]),get(x[5]))
i = i+1
return l
#print 'Begin...'
def getscore():
h =httplib.HTTPConnection('59.67.148.66')
h.connect()
h.request('GET', '/index.asp')
r =h.getresponse()
r.read()
cookie =r.getheader('Set-Cookie')
#print"Cookie: ",cookie
#print 'GetCookie succeed!'
post ={
'Connection':'keep-alive',
'Content-Type':'application/x-www-form-urlencoded',
'Cookie':cookie,
'Referer':'http://59.67.148.66/index.asp',
'Origin':'http://59.67.148.66',
'User-Agent':'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.5(KHTML, like Gecko) Chrome/19.0.1084.52 Safari/536.5'
}
h.request('POST', '/index.asp', msg, post)
r =h.getresponse()
if notr.read().find('Object Moved'):
print 'POST failed!'
exit()
#print'Begin get message...'
post ={
'Host':'59.67.148.66',
'Cookie':cookie
}
h.request('GET','/score/xszxcjcy.asp',headers={'Cookie':cookie})
r =h.getresponse()
s =r.read()
l =score(s)
n =len(l)-1
gpa =0.0
fen =0
for x inl:
if len(x) == 0:
break
fen += int(get(x[6]))
gpa += getgpa(int(get(x[5])))*int(get(x[6]))
printgpa/fen
h.close()
return n
getscore()