kdxcxs
4 years ago
commit
6daf55dce7
3 changed files with 45 additions and 0 deletions
@ -0,0 +1 @@ |
|||||
|
venv/ |
@ -0,0 +1,3 @@ |
|||||
|
# yomooc |
||||
|
|
||||
|
无论是 Android 软件还是网页版的优慕课都是实在难用, 无奈下计划起了这个项目 |
@ -0,0 +1,41 @@ |
|||||
|
""" |
||||
|
A client that simulates the desktop device to communicate with umooc server |
||||
|
""" |
||||
|
|
||||
|
import requests |
||||
|
import time |
||||
|
|
||||
|
|
||||
|
class LoginError(BaseException): |
||||
|
def __init__(self, ErrorInfo): |
||||
|
super().__init__(self) |
||||
|
self.errorinfo = ErrorInfo |
||||
|
|
||||
|
def __str__(self): |
||||
|
return self.errorinfo |
||||
|
|
||||
|
|
||||
|
class UmoocClient(object): |
||||
|
def __init__(self): |
||||
|
self.session = '' |
||||
|
|
||||
|
def login(self, username, password): |
||||
|
resp = requests.post('http://eol.ctbu.edu.cn/meol/loginCheck.do', |
||||
|
headers={'Cache-Control': 'max-age=0', |
||||
|
'Upgrade-Insecure-Requests': '1', |
||||
|
'Origin': 'http://eol.ctbu.edu.cn', |
||||
|
'Content-Type': 'application/x-www-form-urlencoded', |
||||
|
'User-Agent': 'yomooc', |
||||
|
'Referer': 'http://eol.ctbu.edu.cn/meol/common/security/login.jsp?enterLid=46445', |
||||
|
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-US;q=0.7' |
||||
|
}, |
||||
|
data=f'logintoken={str(time.time()).replace(".", "")[:-4]}' |
||||
|
f'&enterLid=46445' |
||||
|
f'&IPT_LOGINUSERNAME={username}' |
||||
|
f'&IPT_LOGINPASSWORD={password}', |
||||
|
allow_redirects=False, |
||||
|
proxies={'http': 'http://127.0.0.1:54385'}) |
||||
|
if resp.status_code == 302: |
||||
|
self.session = resp.cookies['JSESSIONID'] |
||||
|
else: |
||||
|
raise LoginError('Fail to get session') |
Loading…
Reference in new issue