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
评论列表
文章目录