-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
97 lines (78 loc) · 2.16 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
import time
import urllib3
import getpass
import requests
import webbrowser
from bs4 import BeautifulSoup
urllib3.disable_warnings()
URL = 'https://elearn.ut.ac.ir/'
session_req = requests.session()
print('Hi')
username = input('Username: ')
password = getpass.getpass(prompt='Password: ')
# password = input('Password: ')
address = input('Course Online Room Entry Page: ')
login_request = None
while True:
try:
login_request = requests.get(URL, verify=False)
break
except:
error = 0
print('Error')
time.sleep(10)
result = session_req.get(login_request.url, verify=False)
encoding = result.encoding
parser = BeautifulSoup(result.text, "html.parser")
execution = parser.find("input", type="hidden")["value"]
post_data = {'username': username, 'password': password, 'execution': execution,
'_eventId': 'submit', 'submit': 'LOGIN', 'geolocation': ''}
login_result = session_req.post(login_request.url, data=post_data, headers=dict(refer=login_request.url), verify=False)
result = None
while True:
try:
result = session_req.get(address)
break
except:
error = 0
print('Error')
time.sleep(10)
content_parse = BeautifulSoup(result.text, "html.parser")
content = content_parse.find('input', {"value": "پيوستن به كلاس"})
link = content.attrs.get('onclick')
room_session = ""
ses = False
index = str(link).find('sesskey')
while index != len(str(link)):
index += 1
if str(link)[index] == '&':
break
if str(link)[index] == '=':
ses = True
continue
if ses:
room_session += str(link)[index]
# print(room_session)
index = 0
quote_count = 0
vclass_link = ""
while index != len(str(link)):
index += 1
if str(link)[index] == '\'':
quote_count += 1
index += 1
if quote_count == 2:
break
if quote_count == 1:
vclass_link += str(link)[index]
# print(vclass_link)
while True:
try:
result = session_req.get(vclass_link)
break
except:
error = 0
print('Error')
time.sleep(10)
# print(result.url + '&proto=true')
webbrowser.open(result.url + '&proto=true')