View Code? Open in Web Editor
NEW
A package for obtaining and checking v.ruc.edu.cn cookies using selenium (headless) and requests.
Home Page: https://pypi.org/project/ruclogin/
License: MIT License
ruclogin's People
Contributors
Watchers
ruclogin's Issues
当执行ruclogin.py时会有报错,使用的是Edge浏览器配合官方驱动
list index out of range
经检查是处理cookie时split函数出错,即在代码jw_cookies = get_cookies(domain="jw", cache=False)
的时候抛出的异常,也就是经由浏览器驱动获取微人大教务系统时没有正确处理cookie。
将代码修改成:
class RUC_LOGIN :
...
def get_cookies (self , domain = "v" ):
...
elif domain .startswith ("jw" ):
[
self .driver .wait_for_request (
url ,
timeout = 10 ,
)
for url in [
"/Njw2017/index.html*" ,
"/secService/oauthlogin*" ,
]
]
cookies = {}
for request in self .driver .requests :
if request .response :
cookie_header = request .response .headers ["Set-Cookie" ]
if cookie_header :
for cookie in cookie_header .split (", " ):
if "=" in cookie and ";" in cookie :
cookies .update (
{
cookie .split ("=" )[0 ]: cookie .split ("=" )[1 ].split (";" )[0 ]
}
)
return cookies
后正常工作。
原本的代码cookie.split("=")[0]: cookie.split("=")[1].split(";")[0]
假设每个 cookie 都包含至少一个 "=" 和一个 ";"。如果有任何 cookie 不满足这个条件,那么 split("=")[1] 或 split(";")[0] 就会引发 "list index out of range" 错误。
I suggest adopting getpass.getpass
from the Python standard library for password inputs in our GitHub project. This is a common practice that hides passwords from the screen, providing a more secure user experience. It's a standard and effective approach to enhance credential protection in Python applications.
代码中包含**人民大学相关敏感信息,麻烦尽快进行删除。