From eab9874bdbda88807e8a19db4db03ee2038de7c8 Mon Sep 17 00:00:00 2001 From: Saghalt Date: Tue, 11 Jun 2024 10:55:03 +0200 Subject: [PATCH] fix: special attributes cannot be parsed as JSON #312 --- src/kleinanzeigen_bot/extract.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/kleinanzeigen_bot/extract.py b/src/kleinanzeigen_bot/extract.py index eea56b7..612251d 100644 --- a/src/kleinanzeigen_bot/extract.py +++ b/src/kleinanzeigen_bot/extract.py @@ -3,7 +3,7 @@ SPDX-FileCopyrightText: © Sebastian Thomschke and contributors SPDX-License-Identifier: AGPL-3.0-or-later SPDX-ArtifactOfProjectHomePage: https://github.com/Second-Hand-Friends/kleinanzeigen-bot/ """ -import json, logging, os, shutil +import json, logging, os, shutil, re import urllib.request as urllib_request from datetime import datetime from typing import Any, Final @@ -290,7 +290,9 @@ class AdExtractor(WebScrapingMixin): """ belen_conf = await self.web_execute("window.BelenConf") special_attributes_str = belen_conf["universalAnalyticsOpts"]["dimensions"]["dimension108"] - special_attributes = json.loads(special_attributes_str) + # Surrounding any word with " and add curly braces + special_attributes_fixed_str = "{" + re.sub('(\\w+)', '"\\g<1>"', special_attributes_str) + "}" + special_attributes = json.loads(special_attributes_fixed_str) if not isinstance(special_attributes, dict): raise ValueError( "Failed to parse special attributes from ad page."