-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbrowser.py
68 lines (62 loc) · 1.82 KB
/
browser.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
import mechanize
import subprocess
from PIL import Image
import cookielib
from BeautifulSoup import BeautifulSoup
import sys
import time
class Browser:
def __init__(self,url=None):
self.browser = mechanize.Browser()
self.cj = cookielib.LWPCookieJar()
self.browser.set_handle_equiv(True)
self.browser.set_handle_redirect(True)
self.browser.set_handle_referer(True)
self.browser.set_handle_robots(False)
if(url):
self.response = self.browser.open(url)
def open(self,url):
try:
self.response = self.browser.open(url)
except Exception,e:
print '[-] Error: ',str(e)
def read(self):
try:
return self.response.read()
except Exception,e:
print '[-] Error: ',str(e)
return
def getSoup(self):
try:
soup = BeautifulSoup(self.response.read())
return soup
except Exception,e:
print '[-] Error: ',str(e)
def getBrowser(self):
return self.browser
def saveCaptcha(br,captchaurl):
with open('captcha.bmp','w') as f:
f.write(br.open_novisit(captchaurl).read())
def login(regno,passwd):
browser = Browser()
br = browser.getBrowser()
br.open(mainurl)
br.select_form(nr=0)
br['regno']=regno
br['passwd']=passwd
saveCaptcha(br,captchaurl)
p = subprocess.Popen(['display','captcha.bmp'])
vrfcd = raw_input('Enter Verification Code : ')
p.kill()
br['vrfcd']=vrfcd
br.submit()
soup = BeautifulSoup(br.response().read())
print soup
mainurl = 'https://academics.vit.ac.in/student'
captchaurl = 'https://academics.vit.ac.in/student/captcha.asp'
def testing():
regno = 'LOL'
passwd = 'asifimthatstupid'
login(regno,passwd)
if __name__ == '__main__':
testing()