From 7a84806a14105c1642ecb61b38afdb7ced4df8b8 Mon Sep 17 00:00:00 2001 From: Vincent Ardisson Date: Mon, 16 Mar 2020 12:30:34 +0100 Subject: [PATCH] modules: replace cssselect usage with xpath Almost as simple, one dependency less. --- modules/axabanque/pages/bank.py | 2 +- modules/bred/dispobank/pages.py | 2 +- modules/caissedepargne/pages.py | 2 +- modules/creditmutuel/pages.py | 6 +++--- modules/ing/web/accounts_list.py | 4 ++-- modules/jirafeau/pages.py | 2 +- modules/kiwibank/pages.py | 20 ++++++++++---------- modules/societegenerale/sgpe/pages.py | 4 ++-- 8 files changed, 21 insertions(+), 21 deletions(-) diff --git a/modules/axabanque/pages/bank.py b/modules/axabanque/pages/bank.py index 2585a59ae6..873485f01b 100644 --- a/modules/axabanque/pages/bank.py +++ b/modules/axabanque/pages/bank.py @@ -436,7 +436,7 @@ def get_history(self): if len(tables) == 0: tables = self.doc.xpath('//table[@id="table-detail"]') if len(tables) == 0: - tables = self.doc.getroot().cssselect('table.table-detail') + tables = self.doc.xpath('//table[has-class("table-detail")]') if len(tables) == 0: assert len(self.doc.xpath('//td[has-class("no-result")]')) > 0 return diff --git a/modules/bred/dispobank/pages.py b/modules/bred/dispobank/pages.py index ce7c88cabb..251f81e1e7 100644 --- a/modules/bred/dispobank/pages.py +++ b/modules/bred/dispobank/pages.py @@ -63,7 +63,7 @@ def on_load(self): else: self.browser.set_all_readonly(False) accounts = OrderedDict() - for tr in self.doc.getroot().cssselect('table.compteTable > tbody > tr'): + for tr in self.doc.xpath('//table[has-class("compteTable")]/tbody/tr'): if len(tr.findall('td')) == 0: continue attr = tr.xpath('.//a')[0].attrib.get('onclick', '') diff --git a/modules/caissedepargne/pages.py b/modules/caissedepargne/pages.py index 11e5e85fe3..4c7dc40964 100644 --- a/modules/caissedepargne/pages.py +++ b/modules/caissedepargne/pages.py @@ -921,7 +921,7 @@ def get_history(self): continue # Remove useless details - detail = tr.cssselect('div.detail') + detail = tr.xpath('.//div[has-class("detail")]') if len(detail) > 0: detail[0].drop_tree() diff --git a/modules/creditmutuel/pages.py b/modules/creditmutuel/pages.py index 0063a096d2..39194a9ea6 100644 --- a/modules/creditmutuel/pages.py +++ b/modules/creditmutuel/pages.py @@ -1648,11 +1648,11 @@ def obj_iban(self): return l[0].iban def get_account_index(self, direction, account): - for div in self.doc.getroot().cssselect(".dw_dli_contents"): - inp = div.cssselect("input")[0] + for div in self.doc.xpath('//*[has-class("dw_dli_contents")]'): + inp = div.xpath(".//input")[0] if inp.name != direction: continue - acct = div.cssselect("span.doux")[0].text.replace(" ", "") + acct = div.xpath('.//span[has-class("doux")]')[0].text.replace(" ", "") if account.endswith(acct): return inp.attrib['value'] else: diff --git a/modules/ing/web/accounts_list.py b/modules/ing/web/accounts_list.py index 681971d203..a52f50e7a0 100644 --- a/modules/ing/web/accounts_list.py +++ b/modules/ing/web/accounts_list.py @@ -250,11 +250,11 @@ def get_asv_jid(self): return self.doc.xpath('//input[@id="javax.faces.ViewState"]/@value')[0] def islast(self): - havemore = self.doc.getroot().cssselect('.show-more-transactions') + havemore = self.doc.xpath('//*[has-class("show-more-transactions")]') if len(havemore) == 0: return True - nomore = self.doc.getroot().cssselect('.no-more-transactions') + nomore = self.doc.xpath('//*[has-class("no-more-transactions")]') return len(nomore) > 0 @property diff --git a/modules/jirafeau/pages.py b/modules/jirafeau/pages.py index 48b579967b..73acf2691c 100644 --- a/modules/jirafeau/pages.py +++ b/modules/jirafeau/pages.py @@ -50,4 +50,4 @@ def get_max_sizes(self): class PageFile(HTMLPage): def has_error(self): - return bool(self.doc.getroot().cssselect('.error')) + return bool(self.doc.xpath('//*[has-class("error")]')) diff --git a/modules/kiwibank/pages.py b/modules/kiwibank/pages.py index b592cf0f8e..f97f77df32 100644 --- a/modules/kiwibank/pages.py +++ b/modules/kiwibank/pages.py @@ -40,20 +40,20 @@ def login(self, username, password): class AccountPage(LoggedPage, HTMLPage): def get_accounts(self): - for el in self.doc.getroot().cssselect('div#content tr.row'): + for el in self.doc.xpath('//div[@id="content"]//tr[has-class("row")]'): account = Account() - balance = el.cssselect('td.Balance')[0].text + balance = el.xpath('.//td[has-class("Balance")]')[0].text account.balance = Decimal(Transaction.clean_amount(balance)) - account.id = el.cssselect('span')[0].text.strip() + account.id = el.xpath('.//span')[0].text.strip() account.currency = u'NZD' # TODO: handle other currencies account.type = Account.TYPE_CHECKING - if el.cssselect('td.AccountName > a'): - label_el = el.cssselect('td.AccountName > a')[0] + if el.xpath('.//td[has-class("AccountName")]/a'): + label_el = el.xpath('.//td[has-class("AccountName")]/a')[0] account._link = label_el.get('href') else: - label_el = el.cssselect('td.AccountName')[0] + label_el = el.xpath('.//td[has-class("AccountName")]')[0] account._link = None account.label = unicode(label_el.text.strip()) @@ -64,10 +64,10 @@ def get_accounts(self): class HistoryPage(LoggedPage, HTMLPage): def get_history(self): # TODO: get more results from "next" page, only 15 transactions per page - for el in self.doc.getroot().cssselect('div#content tr.row'): + for el in self.doc.xpath('//div[@id="content"]//tr[has-class("row")]'): transaction = Transaction() - label = unicode(el.cssselect('td.tranDesc')[0].text) + label = unicode(el.xpath('.//td[has-class("tranDesc")]')[0].text) transaction.label = label for pattern, _type in Transaction.PATTERNS: @@ -76,10 +76,10 @@ def get_history(self): transaction.type = _type break - date = el.cssselect('td.tranDate')[0].text + date = el.xpath('.//td[has-class("tranDate")]')[0].text transaction.date = datetime.datetime.strptime(date, '%d %b \'%y') - amount = el.cssselect('td.tranAmnt')[0].text + amount = el.xpath('.//td[has-class("tranAmnt")]')[0].text transaction.amount = Decimal(Transaction.clean_amount(amount)) yield transaction diff --git a/modules/societegenerale/sgpe/pages.py b/modules/societegenerale/sgpe/pages.py index 3809a3f576..ebd40ee210 100644 --- a/modules/societegenerale/sgpe/pages.py +++ b/modules/societegenerale/sgpe/pages.py @@ -82,8 +82,8 @@ class Transaction(FrenchTransaction): class SGPEPage(HTMLPage): def get_error(self): - err = self.doc.getroot().cssselect('div.ngo_mire_reco_message') \ - or self.doc.getroot().cssselect('#nge_zone_centre .nge_cadre_message_utilisateur') \ + err = self.doc.xpath('//div[has-class("ngo_mire_reco_message")]') \ + or self.doc.xpath('//*[@id="#nge_zone_centre"]//*[has-class("nge_cadre_message_utilisateur")]') \ or self.doc.xpath(u'//div[contains(text(), "Echec de connexion à l\'espace Entreprises")]') \ or self.doc.xpath(u'//div[contains(@class, "waitAuthJetonMsg")]') if err: -- GitLab