def loginByUser(self, user, url = None): res = True if UrlLoader.loginByUser(self, user, url) == False: return False; signinUrl = self.getUrl() + '/signin' try: cookieJar = ClientCookie.CookieJar() opener = ClientCookie.build_opener( ClientCookie.HTTPCookieProcessor(cookieJar)) opener.addheaders = [("User-agent","Mozilla/5.0 (compatible)")] ClientCookie.install_opener(opener) fp = ClientCookie.urlopen(signinUrl) forms = ClientForm.ParseResponse(fp) fp.close() form = forms[0] form['userName'] = user.get('userName') form['password'] = user.get('password') self._cookie = ClientCookie fpTestOpen = ClientCookie.urlopen(form.click()) fpTestOpen.close() except Exception, e: print('Error when login: ' + e.message) res = False
def __init__(self, url, user, pageId): UrlLoader.__init__(self, url, user) self._id = pageId