def load(self): db = self.__connect() if not db: return cookies = db.execute( """SELECT host, path, name, value, expiry, lastAccessed, isSecure FROM moz_cookies WHERE host LIKE '%%%s%%'""" % self.domain) for entry in cookies: domain = entry[0] initial_dot = domain.startswith(".") domain_specified = initial_dot path = entry[1] name = entry[2] value = entry[3] expires = entry[4] secure = entry[6] discard = False c = Cookie(0, name, value, None, False, domain, domain_specified, initial_dot, path, False, secure, expires, discard, None, None, {}) #if not ignore_discard and c.discard: # continue #if not ignore_expires and c.is_expired(now): # continue self.set_cookie(c)
def change_password(self, current, new): try: vk = BNPVirtKeyboard(self) except VirtKeyboardError as err: self.logger.error("Error: %s" % err) return False from mechanize import Cookie c = Cookie(0, 'wbo_segment_369721', 'AA%7CAB%7C%7C%7C', None, False, '.secure.bnpparibas.net', True, True, '/', False, False, None, False, None, None, {}) cookiejar = self.browser._ua_handlers["_cookies"].cookiejar cookiejar.set_cookie(c) code_current = vk.get_string_code(current) code_new = vk.get_string_code(new) data = ( ('ch1', code_current), ('ch2', code_new), ('radiobutton3', 'radiobutton'), ('ch3', code_new), ('x', 23), ('y', 13), ) headers = {'Referer': self.url} #headers = {'Referer': "https://www.secure.bnpparibas.net/SAF_CHM?Action=SAF_CHM&Origine=SAF_CHM&stp=%s" % (int(datetime.now().strftime('%Y%m%d%H%M%S')))} #import time #time.sleep(10) request = self.browser.request_class( 'https://www.secure.bnpparibas.net/SAF_CHM_VALID', urllib.urlencode(data), headers) self.browser.location(request)
def login(self, login, password): #Paypal use this to check if we accept cookie c = Cookie(0, 'cookie_check', 'yes', None, False, '.' + self.browser.DOMAIN, True, True, '/', False, False, None, False, None, None, {}) cookiejar = self.browser._ua_handlers["_cookies"].cookiejar cookiejar.set_cookie(c) self.browser.select_form(name='login_form') self.browser['login_email'] = login.encode(self.browser.ENCODING) self.browser['login_password'] = password.encode(self.browser.ENCODING) self.browser.submit(nologin=True)
def login(self): assert isinstance(self.username, basestring) assert isinstance(self.password, basestring) assert self.password.isdigit() if not self.is_on_page(LoginPage): self.location('https://' + self.DOMAIN + '/', no_login=True) c = Cookie(0, 'PILOTE_OOBA', 'true', None, False, '.' + self.DOMAIN, True, True, '/', False, False, None, False, None, None, {}) cookiejar = self._ua_handlers["_cookies"].cookiejar cookiejar.set_cookie(c) self.page.login(self.username, self.password) # force page change if not self.is_on_page(AccountsPage): self.accounts(no_login=True) if not self.is_logged(): raise BrowserIncorrectPassword()
def set_cookies(self, cookies, domain='localhost.local', path='/'): """ 1. Set the cookies for this browser. The argument 'cookies' is better be a dict whose keys and values are strings like: browser.set_cookies({'key1': 'value2', 'key2': 'value2'}) 2. 'cookies' could also be a list of mechanize.Cookie objects. """ if isinstance(cookies, tuple): cookies = list(cookies) if isinstance(cookies, dict): cookies = cookies.items() elif not isinstance(cookies, list): raise ValueError('argument cookies should be dict, list or tuple') cookie_objects = [] for c in cookies: if isinstance(c, list) or isinstance(c, tuple): if len(c) != 2: raise ValueError('too many elements, expected: 2') c = Cookie(version=0, name=str(c[0]), value=str(c[1]), port=None, port_specified=False, domain=domain, domain_specified=False, domain_initial_dot=False, path=path, path_specified=False, secure=False, expires=None, discard=True, comment=None, comment_url=None, rest={}) if isinstance(c, Cookie): cookie_objects.append(c) else: raise ValueError('cannot convert %s to a Cookie' % type(c)) for cobj in cookie_objects: self._ua_handlers['_cookies'].cookiejar.set_cookie(cobj)
def add_cookie(self, name, value): c = Cookie(0, name, value, None, False, '.' + self.browser.DOMAIN, True, True, '/', False, False, None, False, None, None, {}) cookiejar = self.browser._ua_handlers["_cookies"].cookiejar cookiejar.set_cookie(c)