Skip to content

Instantly share code, notes, and snippets.

@idlecool
Created October 28, 2012 18:49
Show Gist options
  • Save idlecool/3969447 to your computer and use it in GitHub Desktop.
Save idlecool/3969447 to your computer and use it in GitHub Desktop.
import urllib
from BeautifulSoup import BeautifulSoup
gradedict = {
"A+": 10,
"A": 9.5,
"A-": 9,
"B+": 8.5,
"B": 8,
"B-": 7.5,
"C+": 7,
"C": 6.5,
"C-": 6,
"D": 5,
"E": 4,
}
output = """<!DOCTYPE html>
<html>
<head>
<title>CSE DEPT RESULT</title>
<style type="text/css">
body {
text-align: center;
}
table {
margin: 0 auto;
border-collapse: collapse;
}
th, td
{
border: 1px solid black;
}
td {
padding: 0.5em;
}
</style>
</head>
<body>
<table>
<tr><td><b>Reg No</b></td><td><b>Name</b></td><td><b>GPA</b></td></tr>"""
for reg in xrange(10308000, 10308320):
print reg
try:
url = "http://evarsity.srmuniv.ac.in/srmwebonline/exam/onlineResultInner.jsp?registerno=%s&iden=1" % reg
html = urllib.urlopen(url).read()
soup = BeautifulSoup(html)
a = soup.contents[3]
name = a.contents[2].contents[2].contents[0]
regno = a.contents[4].contents[2].contents[0]
#dept = a.contents[6].contents[2].contents[0]
#coll = a.contents[8].contents[2].contents[0]
result = a.contents[10].contents[3]
resultlist = []
for index in range(3, len(result), 2):
sem = int(result.contents[index].contents[3].contents[0])
if sem == 8:
#code = result.contents[index].contents[5].contents[0]
#subj = result.contents[index].contents[7].contents[0]
cred = int(result.contents[index].contents[9].contents[0])
grade = str(result.contents[index].contents[17].contents[0])
#result = result.contents[index].contents[19].contents[0]
resultlist.append((cred, gradedict[grade]))
totalcredit = 0
gainedgrade = 0
for each in resultlist:
totalcredit += each[0]
gainedgrade += (each[0] * each[1])
gpa = float(gainedgrade)/float(totalcredit)
output += "<tr><td>%s</td><td>%s</td><td>%.2f</td><tr>" % (regno, name, gpa)
except:
pass
output += """</table>
</body>
</html>"""
f = open("result.html", "w")
f.write(output)
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment