do exactly the same thing than js to always get accounts list

This commit is contained in:
Romain Bignon 2014-09-21 12:04:27 +02:00
commit a4083f89a6

View file

@ -21,6 +21,7 @@
from lxml.html import etree from lxml.html import etree
from decimal import Decimal from decimal import Decimal
import re import re
from time import sleep
from weboob.capabilities.bank import Account from weboob.capabilities.bank import Account
from weboob.tools.browser import BasePage, BrowserIncorrectPassword from weboob.tools.browser import BasePage, BrowserIncorrectPassword
@ -88,30 +89,32 @@ class AccountsList(BasePage):
if len(warn) > 0: if len(warn) > 0:
raise BrowserIncorrectPassword(warn[0].text) raise BrowserIncorrectPassword(warn[0].text)
self.load_async(0)
def load_async(self, time):
# load content of loading divs. # load content of loading divs.
divs = [] lst = self.document.xpath('//input[@type="hidden" and starts-with(@id, "asynch")]')
for div in self.document.xpath('//div[starts-with(@id, "as_")]'): if len(lst) > 0:
loading = div.xpath('.//span[@class="loading"]') params = {}
if len(loading) == 0: for i, input in enumerate(lst):
continue params['key%s' % i] = input.attrib['name']
params['div%s' % i] = input.attrib['value']
params['time'] = time
input = div.xpath('.//input')[0] r = self.browser.openurl(self.browser.buildurl('/AsynchAjax', **params))
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))
data = json.load(r) data = json.load(r)
for i, (div, name) in enumerate(divs): for i, d in enumerate(data['data']):
html = data['data'][i]['flux'] div = self.document.xpath('//div[@id="%s"]' % d['key'])[0]
html = d['flux']
div.clear() div.clear()
div.attrib['id'] = d['key'] # needed because clear removes also all attributes
div.insert(0, etree.fromstring(html, parser=etree.HTMLParser())) 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): def need_reload(self):
form = self.document.xpath('//form[@name="InformationsPersonnellesForm"]') form = self.document.xpath('//form[@name="InformationsPersonnellesForm"]')
return len(form) > 0 return len(form) > 0