Created
April 2, 2012 12:26
-
-
Save vikraman/2283121 to your computer and use it in GitHub Desktop.
Gate results grabber
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import urllib | |
from multiprocessing import Pool | |
def fetch_result(regno): | |
try: | |
data = urllib.urlencode({'curyear':'2012', 'rndno':'2988624', 'curregno':regno, 'prevyear':'2011', 'prevregno':'', 'qdeg':'E2', 'qdisc':'ECS', 'mcat':'GN', 'mpd':'N'}) | |
result = urllib.urlopen("http://mtechadm.iitm.ac.in/gform2.php", data) | |
s = result.read() | |
result.close() | |
if s.find('NOT qualified in GATE') != -1: | |
return None | |
else: | |
index1 = s.find('Name of the Candidate') | |
index2 = s.find("<", index1+102) | |
name = s[index1+102:index2] | |
index1 = s.find('GATE Score') | |
index2 = s.find("<b>", index1) | |
index3 = s.find("</b>", index2) | |
score = s[index2+3:index3] | |
return {'name':name.strip(), 'score':score.strip()} | |
except StandardError: | |
pass | |
def get_results(begin): | |
filename = 'result_%d.txt' % (begin) | |
fp = open(filename,'a') | |
for regno in range(begin*1000,(begin+1)*1000): | |
if regno % 100 == 0: | |
fp.flush() | |
res = fetch_result(regno) | |
if res: | |
fp.write('%d\t%s\t%s\n' % (regno, res['score'], res['name'])) | |
fp.close() | |
def main(): | |
regnos = range(6010,6020) | |
p = Pool(5) | |
p.map(get_results, regnos) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment