mirror of
https://github.com/Second-Hand-Friends/kleinanzeigen-bot.git
synced 2026-03-12 02:31:45 +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
|
||||
|
||||
25
pdm.lock
generated
25
pdm.lock
generated
@@ -215,6 +215,15 @@ dependencies = [
|
||||
"attrs>=19.2.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "overrides"
|
||||
version = "6.1.0"
|
||||
requires_python = ">=3.6"
|
||||
summary = "A decorator to automatically detect mismatch when overriding a method."
|
||||
dependencies = [
|
||||
"typing-utils>=0.0.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "packaging"
|
||||
version = "21.3"
|
||||
@@ -483,6 +492,12 @@ version = "4.1.1"
|
||||
requires_python = ">=3.6"
|
||||
summary = "Backported and Experimental Type Hints for Python 3.6+"
|
||||
|
||||
[[package]]
|
||||
name = "typing-utils"
|
||||
version = "0.1.0"
|
||||
requires_python = ">=3.6.1"
|
||||
summary = "utils to inspect Python type annotations"
|
||||
|
||||
[[package]]
|
||||
name = "urllib3"
|
||||
version = "1.26.8"
|
||||
@@ -531,7 +546,7 @@ dependencies = [
|
||||
|
||||
[metadata]
|
||||
lock_version = "3.1"
|
||||
content_hash = "sha256:81a62c2f5f69bee0f964a0ec070894cdde80010a38de4fb6cc2b8a7610033c95"
|
||||
content_hash = "sha256:0950065ae0e85accc6d949ec57598510e1fe569ee0212f9cd225509ab0b091c5"
|
||||
|
||||
[metadata.files]
|
||||
"altgraph 0.17.2" = [
|
||||
@@ -772,6 +787,10 @@ content_hash = "sha256:81a62c2f5f69bee0f964a0ec070894cdde80010a38de4fb6cc2b8a761
|
||||
{file = "outcome-1.1.0-py2.py3-none-any.whl", hash = "sha256:c7dd9375cfd3c12db9801d080a3b63d4b0a261aa996c4c13152380587288d958"},
|
||||
{file = "outcome-1.1.0.tar.gz", hash = "sha256:e862f01d4e626e63e8f92c38d1f8d5546d3f9cce989263c521b2e7990d186967"},
|
||||
]
|
||||
"overrides 6.1.0" = [
|
||||
{file = "overrides-6.1.0-py3-none-any.whl", hash = "sha256:33926e018a952b06309517b3febede982112b86430e588bdd00560b80a4a800b"},
|
||||
{file = "overrides-6.1.0.tar.gz", hash = "sha256:5ba636b73bf72d3d80550f4a5dfe3c7d04ec6e8fd246c4074bfc7ad82bd0ea3d"},
|
||||
]
|
||||
"packaging 21.3" = [
|
||||
{file = "packaging-21.3-py3-none-any.whl", hash = "sha256:ef103e05f519cdc783ae24ea4e2e0f508a9c99b2d4969652eed6a2e1ea5bd522"},
|
||||
{file = "packaging-21.3.tar.gz", hash = "sha256:dd47c42927d89ab911e606518907cc2d3a1f38bbd026385970643f9c5b8ecfeb"},
|
||||
@@ -1008,6 +1027,10 @@ content_hash = "sha256:81a62c2f5f69bee0f964a0ec070894cdde80010a38de4fb6cc2b8a761
|
||||
{file = "typing_extensions-4.1.1-py3-none-any.whl", hash = "sha256:21c85e0fe4b9a155d0799430b0ad741cdce7e359660ccbd8b530613e8df88ce2"},
|
||||
{file = "typing_extensions-4.1.1.tar.gz", hash = "sha256:1a9462dcc3347a79b1f1c0271fbe79e844580bb598bafa1ed208b94da3cdcd42"},
|
||||
]
|
||||
"typing-utils 0.1.0" = [
|
||||
{file = "typing_utils-0.1.0-py3-none-any.whl", hash = "sha256:6bd26f3d38a5dd526ca3a59f0a451ccb59bcee9dc829c872dd6c0aae4ec8bbef"},
|
||||
{file = "typing_utils-0.1.0.tar.gz", hash = "sha256:8ff6b6705414b82575ad5ae0925ac414a9650fb8c5718289b1327dec61252f65"},
|
||||
]
|
||||
"urllib3 1.26.8" = [
|
||||
{file = "urllib3-1.26.8-py2.py3-none-any.whl", hash = "sha256:000ca7f471a233c2251c6c7023ee85305721bfdf18621ebff4fd17a8653427ed"},
|
||||
{file = "urllib3-1.26.8.tar.gz", hash = "sha256:0e7c33d9a63e7ddfcb86780aac87befc2fbddf46c58dbb487e0855f7ceec283c"},
|
||||
|
||||
@@ -28,6 +28,7 @@ requires-python = ">=3.10,<3.11" # <3.11 to get newer versions of pyinstaller
|
||||
dependencies = [
|
||||
"coloredlogs~=15.0",
|
||||
"inflect~=5.4",
|
||||
"overrides~=6.1",
|
||||
"ruamel.yaml~=0.17",
|
||||
"pywin32==303; sys_platform == 'win32'",
|
||||
"selenium~=4.1",
|
||||
|
||||
Reference in New Issue
Block a user