mirror of
https://github.com/Second-Hand-Friends/kleinanzeigen-bot.git
synced 2026-03-12 10:31:50 +01:00
Reload the page in case fullscreen ads is displayed
This commit is contained in:
@@ -9,8 +9,9 @@ import importlib.metadata
|
||||
from logging.handlers import RotatingFileHandler
|
||||
from typing import Any, Final
|
||||
|
||||
from overrides import overrides
|
||||
from ruamel.yaml import YAML
|
||||
from selenium.common.exceptions import NoSuchElementException
|
||||
from selenium.common.exceptions import NoSuchElementException, TimeoutException
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.support import expected_conditions as EC
|
||||
|
||||
@@ -279,7 +280,7 @@ class KleinanzeigenBot(SeleniumMixin):
|
||||
|
||||
def login(self) -> None:
|
||||
LOG.info("Logging in as [%s]...", self.config["login"]["username"])
|
||||
self.web_open(f"{self.root_url}/m-einloggen.html")
|
||||
self.web_open(f"{self.root_url}/m-einloggen.html?targetUrl=/")
|
||||
|
||||
# accept privacy banner
|
||||
self.web_click(By.ID, "gdpr-banner-accept")
|
||||
@@ -461,6 +462,24 @@ class KleinanzeigenBot(SeleniumMixin):
|
||||
|
||||
utils.save_dict(ad_file, ad_cfg_orig)
|
||||
|
||||
@overrides
|
||||
def web_open(self, url:str, timeout:float = 15, reload_if_already_open = False) -> None:
|
||||
start_at = time.time()
|
||||
super().web_open(url, timeout, reload_if_already_open)
|
||||
pause(2000)
|
||||
|
||||
# reload the page until no fullscreen ad is displayed anymore
|
||||
while True:
|
||||
try:
|
||||
self.web_find(By.XPATH, "/html/body/header[@id='site-header']", 2)
|
||||
return
|
||||
except NoSuchElementException as ex:
|
||||
elapsed = time.time() - start_at
|
||||
if elapsed < timeout:
|
||||
super().web_open(url, timeout - elapsed, True)
|
||||
else:
|
||||
raise TimeoutException("Loading page failed, it still shows fullscreen ad.") from ex
|
||||
|
||||
|
||||
#############################
|
||||
# main entry point
|
||||
|
||||
@@ -225,7 +225,7 @@ class SeleniumMixin:
|
||||
input_field.send_keys(text)
|
||||
pause()
|
||||
|
||||
def web_open(self, url:str, timeout:float = 10, reload_if_already_open = False) -> None:
|
||||
def web_open(self, url:str, timeout:float = 15, reload_if_already_open = False) -> None:
|
||||
"""
|
||||
:param url: url to open in browser
|
||||
:param timeout: timespan in seconds within the page needs to be loaded
|
||||
|
||||
Reference in New Issue
Block a user