Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from bs4 import BeautifulSoup
- def getResult(reg, examCode, examYear):
- link='http://www.nu.ac.bd/results/cse/cse_result.php?roll_number=®_no={reg}&exm_code={examCode}&exam_year={examYear}'
- r=get(link.format(reg=reg, examCode=examCode, examYear=examYear))
- soup=BeautifulSoup(r.text, 'html.parser')
- if soup.body.table.tr.td.text=='Error! Wrong Registration Number':
- return {'exception':'student_not_found'}
- else:
- fullList,grades=[],{}
- resultRows1=soup.find_all('table')[1].findAll('tr')
- resultRows2=soup.find_all('table')[2].findAll('tr')[1:]
- name=resultRows1[4].find_all('td')[2].text.strip()
- semester=resultRows1[2].td.text.strip().split()[1].lower()
- try:
- cgpa=float(resultRows1[9].find_all('td')[2].text.strip())
- except:
- cgpa=0
- for result in resultRows2:
- singleList=[]
- for singleResult in result.find_all('td'):
- t=singleResult.text.strip()
- if len(t)==4 and t.isnumeric() and t[0]=='0':
- t='CSE_'+t[1:]
- singleList.append(t)
- grades[singleList[0]]=singleList[3]
- fullList.append(singleList)
- finalJson={'batch':int(str(reg)[0:2])-8, 'cgpa': cgpa, 'courses':fullList, 'exam year':examYear,
- 'exception':'result_found', 'grades':grades, 'name':name, 'registration': reg,
- 'result':'PASSED' if cgpa!=0 else 'FAILED', 'semester':semester,
- 'session':'20'+str(reg)[:2]+'-'+str(int(str(reg)[:2])+1)}
- return finalJson
- # Reg Starts With 17 and 2nd Semester Exam Code 5612 and Exam Year 2018
- # Reg Starts With 17 and 4th Semester Exam Code 5614 and Exam Year 2018
- print(getResult(17502004213, 5612, 2018))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement