-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
141 lines (112 loc) · 4.83 KB
/
main.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import parse
import time
import os
import datetime
import codecs
import getpass
import json
# import urllib2
from bs4 import BeautifulSoup
import requests
#sudo apt-get install xvfb and pip install pyvirtualdisplay to run it in background
#from pyvirtualdisplay import Display
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
def attendance(username,password):
# display = Display(visible=0, size=(800, 600))
# display.start()
baseurl = "http://academicscc.vit.ac.in/student/stud_login.asp"
regno = username
passwd = password
xpaths = { 'usernameTxtBox' : "html/body/table[3]/tbody/tr/td/form/table/tbody/tr/td/table/tbody/tr[2]/td[2]/input[@name='regno']",
'passwordTxtBox' : "html/body/table[3]/tbody/tr/td/form/table/tbody/tr/td/table/tbody/tr[3]/td[2]/input[@name='passwd']",
'captchaTxtBox' : "html/body/table[3]/tbody/tr/td/form/table/tbody/tr/td/table/tbody/tr[5]/td/input[@name='vrfcd']",
'submitButton' : "html/body/table[3]/tbody/tr/td/form/table/tbody/tr/td/table/tbody/tr[6]/td/input[1]"
}
# mydriver = webdriver.Firefox()
mydriver = webdriver.PhantomJS()
mydriver.set_window_size(1120, 550)
test = mydriver.get(baseurl)
#mydriver.maximize_window() this stopped working, dont know why. will check this later
mydriver.execute_script('document.getElementById("imgCaptcha").oncontextmenu = "return true"')
#Clear Username TextBox if already allowed "Remember Me"
mydriver.find_element_by_xpath(xpaths['usernameTxtBox']).clear()
#Write Username in Username TextBox
mydriver.find_element_by_xpath(xpaths['usernameTxtBox']).send_keys(regno)
#Clear Password TextBox if already allowed "Remember Me"
mydriver.find_element_by_xpath(xpaths['passwordTxtBox']).clear()
#Write Password in password TextBox
mydriver.find_element_by_xpath(xpaths['passwordTxtBox']).send_keys(passwd)
#autofill captcha
mydriver.execute_script(open("./captcha.js").read())
#Get Captcha from the user
#vrfcd = raw_input("Please enter the captcha: ")
#Clear Captcha TextBox if already allowed "Remember Me"
#mydriver.find_element_by_xpath(xpaths['captchaTxtBox']).clear()
#Write Captcha in captcha TextBox
#mydriver.find_element_by_xpath(xpaths['captchaTxtBox']).send_keys(vrfcd)
#Click Login button
mydriver.find_element_by_xpath(xpaths['submitButton']).click()
time.sleep(3)
#adding info like date and current semester to the URL's
fromdate = "01-Jan-2017"
todate = datetime.date.today().strftime ("%d-%b-%Y")
month = datetime.datetime.now().strftime("%m")
sem="FS"
if 1<=month and month<=6 or month==12:
sem="WS"
elif month>=7 and month <=11:
sem="FS"
#URL for student profile - html/body/table/tbody/tr/td[2]/table[3]/tbody/tr[2]/td[2]
profileurl = "https://academicscc.vit.ac.in/student/profile_personal_view.asp"
#URL for timetable
timetableurl = "https://academicscc.vit.ac.in/student/course_regular.asp?sem="+sem
#URL for CAT marks (whenever available)
marksurl = "https://academicscc.vit.ac.in/student/marks.asp?sem="+sem
#URL for Academic History
historyurl = "https://academicscc.vit.ac.in/student/student_history.asp"
#URL for attendance
attendanceurl = "https://academicscc.vit.ac.in/student/attn_report.asp?sem="+sem+"&fmdt="+fromdate+"&todt="+todate
mydriver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 't')
mydriver.get(historyurl)
html_source = mydriver.page_source
filename=regno+"_history.html"
text_file = codecs.open(filename, "w", 'utf-8')
text_file.write(html_source)
text_file.close()
mydriver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 't')
mydriver.get(marksurl)
html_source = mydriver.page_source
filename=regno+"_marks.html"
text_file = codecs.open(filename, "w", 'utf-8')
text_file.write(html_source)
text_file.close()
mydriver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 't')
mydriver.get(timetableurl)
html_source = mydriver.page_source
filename=regno+"_timetable.html"
text_file = codecs.open(filename, "w", 'utf-8')
text_file.write(html_source)
text_file.close()
mydriver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 't')
mydriver.get(profileurl)
html_source = mydriver.page_source
filename=regno+"_profile.html"
text_file = codecs.open(filename, "w", 'utf-8')
text_file.write(html_source)
text_file.close()
mydriver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 't')
mydriver.get(attendanceurl)
html_source = mydriver.page_source
filename=regno+"_attendance.html"
text_file = codecs.open(filename, "w", 'utf-8')
text_file.write(html_source)
text_file.close()
result =[[] for i in range(8)]
result = parse.parseatt(filename)
mydriver.quit()
return result