Last active
December 18, 2015 04:09
-
-
Save navinpai/5723561 to your computer and use it in GitHub Desktop.
Get all CBSE Class 12 Results From http://cbseresults.nic.in/class12/cbse122013.htm
This file contains hidden or 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 requests | |
| import os | |
| #Apparently web scraping in now considered *hacking* ... If this is the way India goes, we'll soon be seeing our own 'weev' incident :| | |
| def get_results(i,valid): | |
| params={'regno':i} | |
| print(i) | |
| #Just faking some headers (They're checking the referer... atleast some, albeit weak protection | |
| headers={'Connection':'keep-alive','Accept-Language':'en-US,en;q=0.5','Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8','DNT':'1','User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:21.0) Gecko/20100101 Firefox/21.0','Host': 'cbseresults.nic.in', 'Referer': 'http://cbseresults.nic.in/class12/cbse122013.htm', 'Accept-Encoding': 'gzip, deflate'} | |
| r = requests.post("http://cbseresults.nic.in/class12/cbse122013.asp",data=params,headers=headers) | |
| if(r.text.find("Result Not Found")==-1): | |
| #roll number is valid | |
| valid.write(i+",") | |
| #create and write results to rollnumber.html | |
| a=open(os.path.join(os.getcwd(),i+'.html'),'w') | |
| a.write(r.text) | |
| a.close | |
| if __name__=="__main__": | |
| #Javascript Clientside Validation on the site shows that the first 2 digits should be one of the following... Makes the range to bruteforce much smaller | |
| first_two=[16, 17, 18, 19, 26, 27, 28, 29, 36, 37, 38, 39, 46, 47, 48, 49, 56, 57, 58, 59, 66, 67, 68, 69, 76, 77, 78, 79, 91, 92, 93, 94, 95, 96, 97, 98, 99] | |
| #Just a csv to hold valid roll numbers (incase you want to run it again only for valid numbers) | |
| validroles=open('valid.csv','w') | |
| #Just iterate through the lists and get results :) | |
| for i in first_two: | |
| for k in xrange(10000,99999): | |
| get_results(str(i)+str(k),validroles) | |
| validroles.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment