Skip to content

Instantly share code, notes, and snippets.

@bollu
Created May 27, 2014 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bollu/76c880b6dde598277bd1 to your computer and use it in GitHub Desktop.
Save bollu/76c880b6dde598277bd1 to your computer and use it in GitHub Desktop.
import requests
from bs4 import BeautifulSoup
if __name__ == "__main__":
payload = {'reg': 'AA002', 'frm_tokens' :0.6877558 }
doc = requests.post("http://karresults.nic.in/cetresult2014.asp", data=payload).text
file("a.html", "w").write(doc)
soup = BeautifulSoup(doc)
soup.prettify()
number = soup.select('td[width=146]')[0]
print "Number " + number.font.text
name = soup.select('td[width=224]')[0]
print "Name" + name.text
marks_table = soup.select('table[border="1"]')[0]
#one next_siblingfor whitespace, other for actual sibling
phys_row = marks_table.tr.next_sibling.next_sibling
chem_row = phys_row.next_sibling.next_sibling
maths_row = chem_row.next_sibling.next_sibling
print "Physics" + phys_row.td.next_sibling.next_sibling.next_sibling.text
print "Chem" + chem_row.td.next_sibling.next_sibling.next_sibling.next_sibling.text
print "Maths" + maths_row.td.next_sibling.next_sibling.next_sibling.next_sibling.text
ranks_table = soup.select('table[border="0"]')[2]
engg_rank = ranks_table.tbody.tr.td.table.tr.next_sibling.next_sibling.td.next_sibling.next_sibling.text
print "Engg rank: " + engg_rank
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment