-
Notifications
You must be signed in to change notification settings - Fork 0
/
getcookie.py
53 lines (41 loc) · 1.51 KB
/
getcookie.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
from selenium import webdriver
from selenium.webdriver.edge.service import Service
import time
import os
import downloaddriver as dd
def check_cookie(cookies):
for cookie in cookies:
if cookie['name'] == 'insert_cookie':
insert_cookie = cookie['value']
if cookie['name'] == 'iPlanetDirectoryPro':
iPlanetDirectoryPro = cookie['value']
if cookie['name'] == 'JSESSIONID' and cookie['path'] == '/':
JSESSIONID = cookie['value']
try:
return JSESSIONID, insert_cookie, iPlanetDirectoryPro
except:
return '', '', ''
class GetCookie:
def __init__(self):
try:
browser = webdriver.Edge()
except:
dd.download_driver()
browser = webdriver.Edge()
finally:
# ser = Service()
# if not os.path.exists("./edgedriver_win64/msedgedriver.exe"):
# dd.download_driver()
# ser.path = './edgedriver_win64/msedgedriver.exe'
url = 'https://ugsqs.whu.edu.cn/new/student/'
browser.get(url)
cookies = browser.get_cookies()
# print(browser.current_url.split('/')[2])
while browser.current_url.split('/')[2] == 'cas.whu.edu.cn':
time.sleep(1)
pass
cookies = browser.get_cookies()
# print(cookies)
self.JSESSIONID, self.insert_cookie, self.iPlanetDirectoryPro = check_cookie(cookies)
browser.close()
# c = GetCookie()