[ka6] fix connecteur domainevallierrobert.ca: plugin WP recipe_for_product injecte du HTML avant le JSON REST — ajouter fallback strip-HTML-prefix dans _get_items
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 changed file +16 −2
modified
fabrika/connectors/woocommerce.py
+16 −2
@@ -20,10 +20,24 @@ class WooCommerceConnector(BaseConnector): | ||
| 20 | 20 | try: |
| 21 | 21 | return r.json() |
| 22 | 22 | except ValueError: |
| 23 | + import json as _json | |
| 23 | 24 | # Certains serveurs WP émettent un BOM UTF-8 (\xef\xbb\xbf) avant |
| 24 | 25 | # le JSON — utf-8-sig le retire proprement (ex. cabanedupicbois.com). |
| 25 | − import json as _json | |
| 26 | − return _json.loads(r.content.decode("utf-8-sig")) | |
| 26 | + try: | |
| 27 | + return _json.loads(r.content.decode("utf-8-sig")) | |
| 28 | + except (ValueError, UnicodeDecodeError): | |
| 29 | + pass | |
| 30 | + # Certains plugins WP (ex. recipe_for_product sur | |
| 31 | + # domainevallierrobert.ca) émettent du HTML avant le JSON REST — | |
| 32 | + # on cherche le premier '[' ou '{' et on parse depuis là. | |
| 33 | + for marker in (b"[", b"{"): | |
| 34 | + idx = r.content.find(marker) | |
| 35 | + if idx > 0: | |
| 36 | + try: | |
| 37 | + return _json.loads(r.content[idx:]) | |
| 38 | + except ValueError: | |
| 39 | + pass | |
| 40 | + raise ValueError(f"Impossible de parser le JSON de {url}") | |
| 27 | 41 | except Exception as exc: |
| 28 | 42 | from . import scrapfly |
| 29 | 43 | if scrapfly.available(): |
| 30 | 44 | |