This repository was archived by the owner on May 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfacultyadvisor.py
More file actions
80 lines (57 loc) · 1.83 KB
/
Copy pathfacultyadvisor.py
File metadata and controls
80 lines (57 loc) · 1.83 KB
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
#importing the required modules
from login import login
from bs4 import BeautifulSoup
import threading
#initialising some required variables
faculty_advisor = {}
threadLock = threading.Lock()
threads = []
#overloading thread init and run function
class myThread(threading.Thread):
#overloading the __init__ function
def __init__(self, row):
threading.Thread.__init__(self)
self.row = row
#overloading the run function
def run(self):
threadLock.acquire()
scrape(self.row)
threadLock.release()
#fuction to scrape the row data
def scrape(row):
cells = row.findChildren('td')
if len(cells) == 1:
print "nothing"
else:
faculty_advisor[cells[0].string.replace("\r\n\t\t","")] = cells[1].string.replace("\r\n\t\t","")
#function to return the scraped faculty advisor details
def getFacultyAdvisor(reg_no = "", pwd = ""):
#logging in
br = login(reg_no,pwd)
#checking that are we logged in or not
if br.geturl() == ("https://vtop.vit.ac.in/student/stud_home.asp") or br.geturl() == ("https://vtop.vit.ac.in/student/home.asp"):
print "SUCCESS"
#opening faculty advisor details page
br.open("https://vtop.vit.ac.in/student/faculty_advisor_view.asp")
response = br.open("https://vtop.vit.ac.in/student/faculty_advisor_view.asp")
#getting the soup
soup = BeautifulSoup(response.get_data())
#extracting tables
tables = soup.findChildren('table')
myTable = tables[1]
rows = myTable.findChildren(['th','tr'])
#extracting data
for row in rows:
#creating thread for each row
thrd = myThread(row)
#starting the thread
thrd.start()
#appending into thread list
threads.append(thrd)
#waiting for each thread to complete
for t in threads:
t.join()
return {"status" : "Success" , "faculty_det" : faculty_advisor}
else :
print "FAIL"
return {"Status" : "Failure", "Reason" : "Wrong Captcha"}