[ka2] fix connecteur cara: retry (3 essais, backoff 5/10 s) du rendu Livya via Scrapfly — un raté transitoire (contenu vide/rendu sans cartes, vu 2026-08-29) produisait un faux « 0 trouvé ok »; après 3 essais infructueux le connecteur lève une erreur franche au lieu d'un zéro silencieux
1 changed file +18 −6
modified
louka/connectors/cara.py
+18 −6
@@ -17,6 +17,7 @@ | ||
| 17 | 17 | from __future__ import annotations |
| 18 | 18 | |
| 19 | 19 | import re |
| 20 | +import time | |
| 20 | 21 | |
| 21 | 22 | from bs4 import BeautifulSoup |
| 22 | 23 | |
@@ -57,13 +58,24 @@ class CaraConnector(BaseConnector): | ||
| 57 | 58 | except Exception: |
| 58 | 59 | pass |
| 59 | 60 | |
| 60 | − # 2) app Livya rendue (Next.js : unités chargées côté client) | |
| 61 | + # 2) app Livya rendue (Next.js : unités chargées côté client). Un raté | |
| 62 | + # transitoire Scrapfly (contenu vide ou rendu partiel sans cartes, | |
| 63 | + # vu 2026-08-29) renvoyait 0 annonce « ok » : retry court, puis | |
| 64 | + # erreur franche plutôt qu'un faux zéro. | |
| 61 | 65 | url = LIVYA_FMT.format(project=project, entity=entity) |
| 62 | − html = self.get_scrapfly(url, render_js=True, asp=True, | |
| 63 | − rendering_wait=6000) | |
| 64 | − if not html: | |
| 65 | − return listings | |
| 66 | − soup = BeautifulSoup(html, "html.parser") | |
| 66 | + soup = None | |
| 67 | + for attempt in range(3): | |
| 68 | + html = self.get_scrapfly(url, render_js=True, asp=True, | |
| 69 | + rendering_wait=6000) | |
| 70 | + if html: | |
| 71 | + soup = BeautifulSoup(html, "html.parser") | |
| 72 | + if soup.select("div.Card"): | |
| 73 | + break | |
| 74 | + if attempt < 2: | |
| 75 | + time.sleep(5 * (attempt + 1)) | |
| 76 | + else: | |
| 77 | + raise RuntimeError( | |
| 78 | + "rendu Livya sans cartes d'unités après 3 essais Scrapfly") | |
| 67 | 79 | |
| 68 | 80 | # 3) cartes d'unités : div.Card -> « #116 Disponible 1 810 $ /mois |
| 69 | 81 | # 3½ <ch> <sdb> <pi²> » |
| 70 | 82 | |