-
Notifications
You must be signed in to change notification settings - Fork 20
/
cookie_getter.py
38 lines (33 loc) · 1.31 KB
/
cookie_getter.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
import json
import os
import re
from utils import *
_, URL_DICT = ReadNetWorkJson()
class CookieGetter(Request):
def __init__(self):
super(CookieGetter, self).__init__()
self.loginUrl = URL_DICT['LOGIN']
self.xkUrl = URL_DICT['XK']
self.defaultPage = URL_DICT['MAIN_PAGE']
self.url = URL_DICT['BASE_URL']
self.username, self.password, self.secondMajor = ReadAccountJson()
self.selCourseParams = PayloadGetter('selCourseParams')
self.selCourseParams['username'], self.selCourseParams['password'] = self.username, self.password
def getCookies(self):
req = self.Post(url=self.loginUrl, params=self.selCourseParams, allow_redirects=False)
cookies = req.cookies
if(req.headers['Location'][0] == 'h'):
redirect_url = req.headers['Location']
else:
redirect_url = "".join([self.xkUrl, req.headers['Location']])
req = self.Get(url=redirect_url, cookies=cookies)
redirect_url = re.search("(?<=href=\").*(?=\")", req.text).group(0)
if(redirect_url):
req = self.Get(
url=redirect_url,
cookies=cookies
)
return cookies
if __name__ == '__main__':
cookieGetter = CookieGetter()
cookieGetter.getCookies()