-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.py
59 lines (47 loc) · 1.62 KB
/
index.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
import base64
import io
import sys
import warnings
import requests
from PIL import Image
from bs4 import BeautifulSoup
from CaptchaService import CaptchaParse
headers = {
'User-Agent':
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36'
}
warnings.filterwarnings('ignore', 'Unverified HTTPS request')
unified_session = requests.session()
username = 'your username here'
password = 'your password here'
semester = 'semester ID here' # VL2018191 for Fall 18-19 and VL2018195 for Winter 18-19
url1 = 'https://vtop.vit.ac.in/'
unified_session.get(url1, headers=headers, verify=False)
url1 = 'https://vtop.vit.ac.in/vtop/vtopLogin'
res = unified_session.post(url1, data=None, headers=headers, verify=False)
if 'alt="vtopCaptcha"' not in res.text:
print("Cookies error")
sys.exit()
print("Logging in...")
soup = BeautifulSoup(res.text, 'html.parser')
image = soup.find('img', alt="vtopCaptcha")
image = (image['src'].split(" "))[1]
imgdata = base64.b64decode(image)
image = Image.open(io.BytesIO(imgdata))
captcha = CaptchaParse(image)
data = {
'uname': username,
'passwd': password,
'captchaCheck': captcha
}
url1 = 'https://vtop.vit.ac.in/vtop/doLogin'
res = unified_session.post(url1, data=data, headers=headers, verify=False)
soup = BeautifulSoup(res.text, 'html.parser')
if soup.find('p', {'class': 'box-title text-danger'}) is not None:
error = soup.find('p', {'class': 'box-title text-danger'}).text
print(error)
sys.exit()
print('Logged in successfully')
if res.status_code != 200:
print("Error on VTOP's end. Yeah they suck.")
sys.exit()