def _get_viewstate(self, url=None): response = self.get(url or URL.jwxt_login()) soup = BeautifulSoup(response.content, "lxml") viewstate = soup.find('input', attrs={ "name": "__VIEWSTATE" }).get("value") return viewstate
def login(self, account, password): """ 登录教务系统 jwxt.njupt.edu.cn :param account: 南邮学号 :param password: 密码 :return: {'r': 1, "msg": "登录失败"} 或 {'r': 0, 'msg': '登录成功'} """ data = { "__VIEWSTATE": self._get_viewstate(URL.jwxt_login()), 'txtUserName': account, 'TextBox2': password, 'RadioButtonList1': "%D1%A7%C9%FA", "txtSecretCode": self._get_captcha(URL.jwxt_captcha()), "Button1": "", "hidPdrs": "", "hidsc": "" } result = self._login_execute(url=URL.jwxt_login(), data=data) if result['r'] == 2: # 如果验证码错误,尝试递归重复登录 return self.login(account, password) return result
def login(self, account, password): """ 登录南邮图书馆 jwxt.njupt.edu.cn :param account: 南邮学号 :param password: 密码 :return: {'r': 1, "msg": "登录失败"} 或 {'r': 0, 'msg': '登录成功'} """ data = { "number": account, 'passwd': password, 'captcha': self._get_captcha(URL.lib_captcha()), 'select': "cert_no", "returnUrl": "", } return self._login_execute(url=URL.jwxt_login(), data=data)