예제 #1
0
    def login(self):
        """
        登陆程序,只要把该发的都发过去就行了,还有这里的Token更新了
        :return:
        """
        url = self.orgin_host + "auth/signIn"
        data_to_send = {
            "SYNCHRONIZER_TOKEN": self.synchronizer_token,
            "SYNCHRONIZER_URI": "/login",
            "username": self.config["username"],
            "password": self.config["password"],
            "authid": self.authid,
        }
        response = self.post(url, data=data_to_send).text
        self.headers.update({"Referer": self.orgin_host})

        if not re.search(
                r'(?<=<a id="btnStop" href="#" action="stopUsing">).+?(?=</a>)',
                response):
            raise utils.LoginError("登陆失败")

        synchronizer_token = re.search(
            '(?<=name="SYNCHRONIZER_TOKEN" value=").+?(?=")',
            response).group()

        self.synchronizer_token = synchronizer_token
        print("【网页端登陆成功】")
예제 #2
0
 def login(self):
     """
         用于模拟自习助手的登陆,从而实现绕过验证码
         :return: token, string 系统用token验证身份
     """
     url = "rest/auth?username={0}&password={1}".format(
         self.config["username"], self.config["password"])
     response = self.req_with_json(url)
     if response["status"] == "fail":
         raise utils.LoginError("账号或密码不正确,请修改同目录下config.json中的账号和密码")
     token = response["data"]["token"]
     self.headers["token"] = token  # 自动更新headers,加入token记录登陆信息
     print("【APP端登陆成功】")
예제 #3
0
    def get_synchronizer_token(self):
        """
        获取一个token,用作身份识别
        :return: synchronizer token
        """
        self.headers.update({"Origin": self.orgin_host})
        url = self.orgin_host + "login?targetUri=%2F"
        response = self.get(url).text
        self.headers.update({"Referer": url})

        try:
            token = re.search(
                r'(?<=name="SYNCHRONIZER_TOKEN" value=").+?(?=")',
                response).group()
        except AttributeError:
            raise utils.LoginError("无法访问网页,请检查当前网络状态;或者图书馆网站正在维护")

        return token