mirror of
https://github.com/Second-Hand-Friends/kleinanzeigen-bot.git
synced 2026-03-12 10:31:50 +01:00
fix: special attributes cannot be parsed as JSON #312
This commit is contained in:
@@ -3,7 +3,7 @@ SPDX-FileCopyrightText: © Sebastian Thomschke and contributors
|
|||||||
SPDX-License-Identifier: AGPL-3.0-or-later
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
SPDX-ArtifactOfProjectHomePage: https://github.com/Second-Hand-Friends/kleinanzeigen-bot/
|
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
|
import urllib.request as urllib_request
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Any, Final
|
from typing import Any, Final
|
||||||
@@ -290,7 +290,9 @@ class AdExtractor(WebScrapingMixin):
|
|||||||
"""
|
"""
|
||||||
belen_conf = await self.web_execute("window.BelenConf")
|
belen_conf = await self.web_execute("window.BelenConf")
|
||||||
special_attributes_str = belen_conf["universalAnalyticsOpts"]["dimensions"]["dimension108"]
|
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):
|
if not isinstance(special_attributes, dict):
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"Failed to parse special attributes from ad page."
|
"Failed to parse special attributes from ad page."
|
||||||
|
|||||||
Reference in New Issue
Block a user