From 06b947b0fc3c2367905593b540a7fc1494eeded5 Mon Sep 17 00:00:00 2001 From: Jeppy Date: Sat, 5 Nov 2022 18:19:33 +0100 Subject: [PATCH] FIX Extract correct special attributes of ad page --- kleinanzeigen_bot/extract.py | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/kleinanzeigen_bot/extract.py b/kleinanzeigen_bot/extract.py index f69dbd0..79c7d74 100644 --- a/kleinanzeigen_bot/extract.py +++ b/kleinanzeigen_bot/extract.py @@ -3,6 +3,7 @@ Copyright (C) 2022 Sebastian Thomschke and contributors SPDX-License-Identifier: AGPL-3.0-or-later """ from decimal import DecimalException +import json from selenium.common.exceptions import NoSuchElementException from selenium.webdriver.common.by import By @@ -41,20 +42,12 @@ class AdExtractor: :return: a dictionary (possibly empty) where the keys are the attribute names, mapped to their values """ - - try: - details_box = self.driver.find_element(By.CSS_SELECTOR, '#viewad-details') - details_list = details_box.find_element(By.XPATH, './/ul') - list_items = details_list.find_elements(By.TAG_NAME, 'li') - details = {} - for list_item in list_items: - detail_key = list_item.text.split('\n')[0] - detail_value = list_item.find_element(By.TAG_NAME, 'span').text - details[detail_key] = detail_value - - return details - except NoSuchElementException: - return {} + belen_conf = self.driver.execute_script("return window.BelenConf") + special_attributes_str = belen_conf["universalAnalyticsOpts"]["dimensions"]["dimension108"] + special_attributes = json.loads(special_attributes_str) + assert isinstance(special_attributes, dict) + special_attributes = {k: v for k, v in special_attributes.items() if not k.endswith('.versand_s')} + return special_attributes def extract_pricing_info_from_ad_page(self) -> (float | None, str): """