-
Notifications
You must be signed in to change notification settings - Fork 0
/
result_extractor.py
68 lines (56 loc) · 2.38 KB
/
result_extractor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from bs4 import BeautifulSoup
from pandas import DataFrame
from io import StringIO
import sys
path = 'C:/MAKAUT-Result-Extractor/'
def extract_results(roll_no, semester_no):
options = webdriver.FirefoxOptions()
options.headless = True
driver = webdriver.Firefox(executable_path=path+'geckodriver.exe', options=options)
driver.get('https://makaut.ucanapply.com/smartexam/public/result-details')
elem = driver.find_element_by_id("username")
elem.send_keys(roll_no)
select = Select(driver.find_element_by_id('semester'))
select.select_by_value('SM' + semester_no)
elem = driver.find_element_by_class_name('btn.btn-warning')
elem.click()
page_source = driver.page_source
driver.quit()
if 'Result under process!' not in page_source:
soup = BeautifulSoup(page_source, "lxml")
result = soup.findAll('tbody')
personal_details = []
for i in result[1].findAll('td'):
personal_details.append(i.text.strip(' \xa0\n').replace('\xa0', ''))
score_sheet = []
for i in result[3].findAll('tr'):
row = []
for j in i.findAll('td'):
row.append(j.text.strip(' \xa0\n').replace('\xa0', ''))
score_sheet.append(row)
score_sheet_df = DataFrame(score_sheet[1:], columns=score_sheet[0])
stats = []
for i in result[5].findAll('tr')[:-1]:
stats.append(i.findAll('td')[0].text.strip(' \xa0\n').replace('\xa0', ''))
mar = []
for i in result[6].findAll('td'):
mar.append(i.text.strip(' \xa0\n').replace('\xa0', ''))
old_stdout = sys.stdout
text_to_be_written = StringIO()
sys.stdout = text_to_be_written
print(*personal_details, sep='\n\n', end='\n\n')
print(score_sheet_df.to_string(index=False), end='\n\n')
print(*stats, sep='\n', end='\n\n')
print(*mar)
stdout = old_stdout
with open(path+roll_no+'_'+semester_no+'.txt', 'w') as fp:
fp.write(text_to_be_written.getvalue())
return True
return False
if __name__ == '__main__':
roll_no = input('Enter your MAKAUT roll number:')
semester_no = '0' + input('Enter your semester number <1-8>: ')
extract_results(roll_no, semester_no)