From e71d65f04fc6a4c3fd78906a5aa6bfec8f9905c8 Mon Sep 17 00:00:00 2001 From: Jean-Marie Favreau Date: Fri, 16 Aug 2024 13:34:44 +0200 Subject: [PATCH] on ajoute des try/catches --- .../import_tasks/downloader.py | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/agenda_culturel/import_tasks/downloader.py b/src/agenda_culturel/import_tasks/downloader.py index 6052461..a2f74a5 100644 --- a/src/agenda_culturel/import_tasks/downloader.py +++ b/src/agenda_culturel/import_tasks/downloader.py @@ -86,6 +86,30 @@ class ChromiumHeadlessDownloader(Downloader): raise Exception("POST method with Chromium headless not yet implemented") print("Download {}".format(url)) - self.driver.get(url) - doc = self.driver.page_source + try: + self.driver.get(url) + doc = self.driver.page_source + + except exceptions.StaleElementReferenceException as e: + print(f">> {type(e).__name__}: {e.args}") + return None + except exceptions.NoSuchElementException as e: + print(f">> {type(e).__name__}: {e.args}") + return None + except exceptions.TimeoutException as e: + print(f">> {type(e).__name__}: {e.args}") + return None + except exceptions.WebDriverException as e: + print(f">> {type(e).__name__}: {e.args}") + return None + except exceptions.SessionNotCreatedException as e: + print(f">> {type(e).__name__}: {e.args}") + return None + except Exception as e: + print(f">> {type(e).__name__} line {e.__traceback__.tb_lineno} of {__file__}: {e.args}") + return None + except: + print(f">> General Exception: {URL}") + return None + return doc