From a4083f89a6d818994aafe68d0d4513bfda875e93 Mon Sep 17 00:00:00 2001 From: Romain Bignon Date: Sun, 21 Sep 2014 12:04:27 +0200 Subject: [PATCH] do exactly the same thing than js to always get accounts list --- modules/fortuneo/pages/accounts_list.py | 39 +++++++++++++------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/modules/fortuneo/pages/accounts_list.py b/modules/fortuneo/pages/accounts_list.py index 73fcb60192..7549c6f5fe 100644 --- a/modules/fortuneo/pages/accounts_list.py +++ b/modules/fortuneo/pages/accounts_list.py @@ -21,6 +21,7 @@ from lxml.html import etree from decimal import Decimal import re +from time import sleep from weboob.capabilities.bank import Account from weboob.tools.browser import BasePage, BrowserIncorrectPassword @@ -88,30 +89,32 @@ def on_loaded(self): if len(warn) > 0: raise BrowserIncorrectPassword(warn[0].text) + self.load_async(0) + + def load_async(self, time): # load content of loading divs. - divs = [] - for div in self.document.xpath('//div[starts-with(@id, "as_")]'): - loading = div.xpath('.//span[@class="loading"]') - if len(loading) == 0: - continue - - input = div.xpath('.//input')[0] - divs.append([div, input.attrib['name']]) - - if len(divs) > 0: - args = {} - for i, (div, name) in enumerate(divs): - args['key%s' % i] = name - args['div%s' % i] = div.attrib['id'] - args['time'] = 0 - r = self.browser.openurl(self.browser.buildurl('/AsynchAjax', **args)) + lst = self.document.xpath('//input[@type="hidden" and starts-with(@id, "asynch")]') + if len(lst) > 0: + params = {} + for i, input in enumerate(lst): + params['key%s' % i] = input.attrib['name'] + params['div%s' % i] = input.attrib['value'] + params['time'] = time + + r = self.browser.openurl(self.browser.buildurl('/AsynchAjax', **params)) data = json.load(r) - for i, (div, name) in enumerate(divs): - html = data['data'][i]['flux'] + for i, d in enumerate(data['data']): + div = self.document.xpath('//div[@id="%s"]' % d['key'])[0] + html = d['flux'] div.clear() + div.attrib['id'] = d['key'] # needed because clear removes also all attributes div.insert(0, etree.fromstring(html, parser=etree.HTMLParser())) + if 'time' in data: + sleep(float(data['time'])/1000.0) + return self.load_async(time) + def need_reload(self): form = self.document.xpath('//form[@name="InformationsPersonnellesForm"]') return len(form) > 0 -- GitLab