SessionAPI.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:competitive-cli 作者: GDGVIT 项目源码 文件源码
def login(self, username, password):
        """
        logs the user in and returns a bool value
        stores the username in self.username.
        """
        get_response = self.uva_session.get(UvaSession.UVA_HOST)
        login_text = lxml.html.fromstring(get_response.text)
        hidden_inputs = login_text.xpath(r'//form//input[@type="hidden"]')
        # print hidden_inputs
        form = {x.attrib["name"]: x.attrib["value"] for x in hidden_inputs if x.attrib['name'] not in ["cx", "ie"]}
        form["username"] = username
        form["passwd"] = password
        form["remember"] = "yes"
        login_response = self.uva_session.post(UvaSession.UVA_HOST + "index.php?option=com_comprofiler&task=login",
                                               data=form, headers={"referer": UvaSession.UVA_HOST})

        self.logged_in = login_response.url == UvaSession.UVA_HOST
        if (self.logged_in): self.username = username
        return self.logged_in
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号