forked from GDGVIT/studentLogin_API_tornado
-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.py
66 lines (50 loc) · 1.43 KB
/
login.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
def login(reg_no="",pwd=""):
#importing the required modules
from bs4 import BeautifulSoup
from CaptchaParser import CaptchaParser
from PIL import Image
import mechanize
import os
#handeling browser and browser initialisation
br = mechanize.Browser()
br.set_handle_robots(False)
br.set_handle_equiv(True)
br.set_handle_gzip(True)
br.set_handle_redirect(True)
br.set_handle_referer(True)
#opening website
response = br.open("https://vtop.vit.ac.in/student/stud_login.asp")
#print br.geturl()
#selecting the login form
br.select_form("stud_login")
#extracting captcha url
soup = BeautifulSoup(response.get_data())
img = soup.find('img', id='imgCaptcha')
#print img['src']
#retrieving captcha image
br.retrieve("https://vtop.vit.ac.in/student/"+img['src'], reg_no+".bmp")
print "captcha retrieved"
#opening the image
img = Image.open(reg_no+".bmp")
#parsing the image and getting its string value
parser = CaptchaParser()
captcha = parser.getCaptcha(img)
print str(captcha)
os.remove(reg_no+".bmp")
#filling form
br["regno"] = str(reg_no)
br["passwd"] = str(pwd)
br["vrfcd"] = str(captcha)
#submitting the values and signing in
br.method = "POST"
response = br.submit()
#during the time of rivera
try:
br.open("https://vtop.vit.ac.in/student/stud_home.asp")
br.select_form("stud_riviera")
br.submit(label = "Skip Now")
print "Login_Sucess"
#for normal login
except:
print "Login_Sucess"
return br