diff --git a/modules/caissedepargne/backend.py b/modules/caissedepargne/backend.py index 5f79e800..5bc4cdee 100644 --- a/modules/caissedepargne/backend.py +++ b/modules/caissedepargne/backend.py @@ -20,7 +20,7 @@ from weboob.capabilities.bank import ICapBank, AccountNotFound from weboob.tools.backend import BaseBackend, BackendConfig -from weboob.tools.value import ValueBackendPassword +from weboob.tools.value import Value, ValueBackendPassword from .browser import CaisseEpargne @@ -36,11 +36,13 @@ class CaisseEpargneBackend(BaseBackend, ICapBank): DESCRIPTION = u'Caisse d\'Épargne French bank website' LICENSE = 'AGPLv3+' CONFIG = BackendConfig(ValueBackendPassword('login', label='Account ID', masked=False), - ValueBackendPassword('password', label='Password', regexp='\d+')) + ValueBackendPassword('password', label='Password', regexp='\d+'), + Value('nuser', label='User ID (optional)', default='')) BROWSER = CaisseEpargne def create_default_browser(self): - return self.create_browser(self.config['login'].get(), + return self.create_browser(self.config['nuser'].get(), + self.config['login'].get(), self.config['password'].get()) def iter_accounts(self): diff --git a/modules/caissedepargne/browser.py b/modules/caissedepargne/browser.py index 091a15a0..bac8a0a0 100644 --- a/modules/caissedepargne/browser.py +++ b/modules/caissedepargne/browser.py @@ -39,6 +39,10 @@ class CaisseEpargne(BaseBrowser): 'https://[^/]+.caisse-epargne.fr/page_hs_dei_.*.aspx': UnavailablePage, } + def __init__(self, nuser, *args, **kwargs): + self.nuser = nuser + BaseBrowser.__init__(self, *args, **kwargs) + def is_logged(self): return self.page is not None and not self.is_on_page((LoginPage,ErrorPage)) @@ -64,8 +68,9 @@ class CaisseEpargne(BaseBrowser): self.location('https://www.caisse-epargne.fr/particuliers/ind_pauthpopup.aspx?mar=101®=&fctpopup=auth&cv=0', no_login=True) self.page.login(self.username) - self.page.login2() - self.page.login3(self.password) + if not self.page.login2(self.nuser, self.password): + # perso + self.page.login3(self.password) if not self.is_logged(): raise BrowserIncorrectPassword() diff --git a/modules/caissedepargne/pages.py b/modules/caissedepargne/pages.py index 6ead7fde..88289949 100644 --- a/modules/caissedepargne/pages.py +++ b/modules/caissedepargne/pages.py @@ -50,13 +50,23 @@ class LoginPage(_LogoutPage): self.browser['__EVENTTARGET'] = 'ctl01$CC_ind_pauthpopup$ctl01$CC_ind_ident$ctl01$CC_ind_inputuserid_sup$btnValider' self.browser.submit(nologin=True) - def login2(self): + def login2(self, nuser, passwd): self.browser.select_form(name='Main') self.browser.set_all_readonly(False) self.browser['__EVENTARGUMENT'] = 'idsrv=WE' + + a = self.document.xpath('//a[@title="Valider"]')[0] + m = re.match("javascript:RedirectToDeiPro\('([^']+)', \d+\);", a.attrib['href']) + if m: + self.browser['nuusager'] = nuser.encode('utf-8') + self.browser['codconf'] = passwd.encode('utf-8') + self.browser.form.action = m.group(1) + self.browser.submit(nologin=True) - def login3(self, passwd): + return m is not None + + def login3(self, nuser, passwd): self.browser.select_form(name='Main') self.browser['codconf'] = passwd.encode('utf-8') a = self.document.xpath('//a[@title="Valider"]')[0] @@ -124,7 +134,7 @@ class IndexPage(BasePage): def _add_account(self, accounts, link, label, account_type, balance): info = self._get_account_info(link) if info is None: - self.logger.warning('Unable to parse account %r' % label) + self.logger.warning('Unable to parse account %r: %r' % (label, link)) return account = Account() @@ -157,12 +167,25 @@ class IndexPage(BasePage): if tr.attrib.get('class', '') == 'DataGridHeader': account_type = self.ACCOUNT_TYPES.get(tds[1].text.strip(), Account.TYPE_UNKNOWN) else: - a = tds[1].find('a') - if a is None: - continue + label = '' + i = 1 + a = None + while label == '' and i < len(tds): + a = tds[i].find('a') + if a is None: + continue - label = self.parser.tocleanstring(a) - balance = u''.join([txt.strip() for txt in tds[-1].itertext()]) + label = self.parser.tocleanstring(a) + i += 1 + + balance = '' + i = -1 + while balance == '' and i > -len(tds): + try: + balance = self.parser.tocleanstring(tds[i].xpath('./a')[0]) + except KeyError: + balance = u''.join([txt.strip() for txt in tds[i].itertext()]) + i -= 1 self._add_account(accounts, a, label, account_type, balance) if len(accounts) == 0: