forked from ZHtwinkle/Lecture_Assistant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlec.py
50 lines (47 loc) · 1.77 KB
/
lec.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
from DrissionPage import ChromiumPage
import base64
from PIL import Image
from io import BytesIO
from bd_api import get_code
import time
import config
def get_session_id():
page = ChromiumPage()
flag = True
while flag:
try:
page.get('http://sjcx.buct.edu.cn/')
img = page('@flag=VIMG')
src = img.src()
base64_string = base64.b64encode(src).decode()
image_data = base64.b64decode(base64_string)
img = Image.open(BytesIO(image_data))
img.save('output_image.png')
validate_code = get_code()
print(validate_code)
username = config.username
password = config.password
ele_username = page.ele("@name=username")
ele_username.clear()
ele_username.input(username)
ele_password = page.ele("@name=password")
ele_password.clear()
ele_password.input(password)
ele_validate_code = page.ele("@name=validateCode")
ele_validate_code.clear()
ele_validate_code.input(validate_code)
ele_juese = page.ele("@name=juese")
ele_juese.select.by_value(2)
ele_submit = page.ele("@type=submit")
ele_submit.click()
time.sleep(2)
flag = page.handle_alert(timeout=0.5)
print("验证码正确" if not flag else "验证码错误")
ele_title = page.ele('xpath:/html/body/dl/dd[7]/div')
ele_title.click()
for i in page.cookies(as_dict=False):
if i.get("name", 0) == "aexpsid":
return i["value"].split(".")[0]
except Exception as E:
print(E)
continue