From 3e69d5cc14e7c49d967b288824ced9f0ebe28cce Mon Sep 17 00:00:00 2001 From: Vincent Ardisson Date: Thu, 9 Nov 2017 10:09:15 +0100 Subject: [PATCH] [spirica] fix investment info fetch when label contains a quote It doesn't seem easy to quote in xpath, so do a plain-old for-loop. --- modules/spirica/pages.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/modules/spirica/pages.py b/modules/spirica/pages.py index 698dc2e5ee..b668a0af54 100644 --- a/modules/spirica/pages.py +++ b/modules/spirica/pages.py @@ -150,13 +150,22 @@ class iter_investment(TableInvestment): class item(ItemInvestment): obj_code = Regexp(CleanText('.//td[contains(text(), "Isin")]'), ':[\s]+([\w]+)', default=NotAvailable) + def invest_link(self): + label = Field('label')(self) + for a in self.el.xpath('//div[contains(@id, "PRIX_REVIENT")]//a'): + if label in CleanText('.')(a): + return a + assert 'fonds euro' in label.lower() + def obj_unitprice(self): - return MyDecimal('//div[contains(@id, "PRIX_REVIENT")]//a[contains(text(), \ - "%s")]/ancestor::tr/td[5]' % Field('label')(self))(self) + link = self.invest_link() + if link: + return MyDecimal('./ancestor::tr/td[5]')(link) def obj_diff(self): - return MyDecimal('//div[contains(@id, "PRIX_REVIENT")]//a[contains(text(), \ - "%s")]/ancestor::tr/td[6]' % Field('label')(self))(self) + link = self.invest_link() + if link: + return MyDecimal('./ancestor::tr/td[6]')(link) def obj_portfolio_share(self): inv_share = ItemInvestment.obj_portfolio_share(self) -- GitLab