mirror of
https://github.com/Second-Hand-Friends/kleinanzeigen-bot.git
synced 2026-03-12 18:41:50 +01:00
FIX Extract correct special attributes of ad page
This commit is contained in:
committed by
Sebastian Thomschke
parent
a50dead2a7
commit
06b947b0fc
@@ -3,6 +3,7 @@ Copyright (C) 2022 Sebastian Thomschke and contributors
|
|||||||
SPDX-License-Identifier: AGPL-3.0-or-later
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
"""
|
"""
|
||||||
from decimal import DecimalException
|
from decimal import DecimalException
|
||||||
|
import json
|
||||||
|
|
||||||
from selenium.common.exceptions import NoSuchElementException
|
from selenium.common.exceptions import NoSuchElementException
|
||||||
from selenium.webdriver.common.by import By
|
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
|
:return: a dictionary (possibly empty) where the keys are the attribute names, mapped to their values
|
||||||
"""
|
"""
|
||||||
|
belen_conf = self.driver.execute_script("return window.BelenConf")
|
||||||
try:
|
special_attributes_str = belen_conf["universalAnalyticsOpts"]["dimensions"]["dimension108"]
|
||||||
details_box = self.driver.find_element(By.CSS_SELECTOR, '#viewad-details')
|
special_attributes = json.loads(special_attributes_str)
|
||||||
details_list = details_box.find_element(By.XPATH, './/ul')
|
assert isinstance(special_attributes, dict)
|
||||||
list_items = details_list.find_elements(By.TAG_NAME, 'li')
|
special_attributes = {k: v for k, v in special_attributes.items() if not k.endswith('.versand_s')}
|
||||||
details = {}
|
return special_attributes
|
||||||
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 {}
|
|
||||||
|
|
||||||
def extract_pricing_info_from_ad_page(self) -> (float | None, str):
|
def extract_pricing_info_from_ad_page(self) -> (float | None, str):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user