From e9ed28104c265d7c109dc3d2d796b3d194221ddf Mon Sep 17 00:00:00 2001 From: Quentin Defenouillere Date: Thu, 20 Aug 2020 11:59:40 +0200 Subject: [PATCH] [amundi] Handle bugs on CprInvestmentsPage Some investments lead to a 404 (even on the website) and we have to handle unavailable SRRI. --- modules/amundi/browser.py | 9 ++++++--- modules/amundi/pages.py | 7 ++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/modules/amundi/browser.py b/modules/amundi/browser.py index 41f80cf1b4..79e2b642e6 100644 --- a/modules/amundi/browser.py +++ b/modules/amundi/browser.py @@ -21,7 +21,9 @@ from weboob.browser import URL, LoginBrowser, need_login from weboob.exceptions import BrowserIncorrectPassword -from weboob.browser.exceptions import ClientError, ServerError +from weboob.browser.exceptions import ( + ClientError, ServerError, BrowserHTTPNotFound, +) from weboob.capabilities.base import empty, NotAvailable from .pages import ( @@ -138,8 +140,9 @@ def fill_investment_details(self, inv): # This method handles all the already encountered pages. try: self.location(inv._details_url) - except ServerError: - # Some URLs return a 500 even on the website + except (ServerError, BrowserHTTPNotFound): + # Some URLs return a 500 or a 404 even on the website + self.logger.warning('Details are not available for this investment.') inv.asset_category = NotAvailable inv.recommended_period = NotAvailable return inv diff --git a/modules/amundi/pages.py b/modules/amundi/pages.py index 1254ca37f2..623d545395 100644 --- a/modules/amundi/pages.py +++ b/modules/amundi/pages.py @@ -314,11 +314,16 @@ def obj_performance_history(self): class CprInvestmentPage(LoggedPage, HTMLPage): @method class fill_investment(ItemElement): - obj_srri = CleanText('//span[@class="active"]', default=NotAvailable) # Text headers can be in French or in English obj_asset_category = Title('//div[contains(text(), "Classe d\'actifs") or contains(text(), "Asset class")]//strong', default=NotAvailable) obj_recommended_period = Title('//div[contains(text(), "Durée recommandée") or contains(text(), "Recommended duration")]//strong', default=NotAvailable) + def obj_srri(self): + srri = CleanText('//span[@class="active"]')(self) + # 'srri' can sometimes be an empty string, so we keep + # the value scraped on the Amundi website + return srri or self.obj.srri + def get_performance_url(self): js_script = CleanText('//script[@language="javascript"]')(self.doc) # beurk # Extract performance URL from a string such as 'Product.init(false,"/particuliers..."' -- GitLab