-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathids.py
62 lines (51 loc) · 1.93 KB
/
ids.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
import requests
from lxml import etree
class IdsAuth:
cookies = {}
ok = False
headers = {
'User-Agent':
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) '
'AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/106.0.0.0 Safari/537.36',
}
s = requests.Session()
rVerify = True # or 'mitm.pem'
def __init__(self, cookies=None):
if cookies:
self.s.cookies = requests.utils.cookiejar_from_dict(cookies)
self.cookies = self.s.cookies.get_dict()
self.check()
def login(self, username: str, password: str, service: str):
url = 'https://ids.shiep.edu.cn/authserver/login'
resp = self.s.get(url,
params={'service': service},
headers=self.headers,
verify=self.rVerify)
e = etree.HTML(resp.text)
form = {
i.get('name'): i.get('value')
for i in e.xpath('//form//input')
}
form['username'] = username
form['password'] = password
resp = self.s.post(url,
params={'service': service},
data=form,
headers=self.headers,
verify=self.rVerify)
self.cookies = self.s.cookies.get_dict()
self.check()
def check(self):
url = 'https://jw.shiep.edu.cn/eams/home.action'
resp = self.s.get(url,
headers=self.headers,
verify=self.rVerify,
allow_redirects=False)
self.ok = (resp.status_code == 200)
def get(self, url: str, **kwargs):
return self.s.get(url, verify=self.rVerify, **kwargs)
def post(self, url: str, **kwargs):
return self.s.post(url, verify=self.rVerify, **kwargs)
def head(self, url: str, **kwargs):
return self.s.head(url, verify=self.rVerify, **kwargs)