mirror of
https://github.com/Second-Hand-Friends/kleinanzeigen-bot.git
synced 2026-03-12 02:31:45 +01:00
fix: login does not work anymore #539
Refactored login input element ids. Refactored captcha handling to one function
This commit is contained in:
committed by
Sebastian Thomschke
parent
c6e8175670
commit
8ac57932ba
@@ -492,6 +492,26 @@ class KleinanzeigenBot(WebScrapingMixin):
|
||||
self.browser_config.user_data_dir = abspath(self.config.browser.user_data_dir, relative_to = self.config_file_path)
|
||||
self.browser_config.profile_name = self.config.browser.profile_name
|
||||
|
||||
async def check_and_wait_for_captcha(self, *, is_login_page:bool = True) -> None:
|
||||
try:
|
||||
await self.web_find(By.CSS_SELECTOR,
|
||||
"iframe[name^='a-'][src^='https://www.google.com/recaptcha/api2/anchor?']", timeout = 2)
|
||||
|
||||
if not is_login_page and self.config.captcha.auto_restart:
|
||||
LOG.warning("Captcha recognized - auto-restart enabled, abort run...")
|
||||
raise CaptchaEncountered(misc.parse_duration(self.config.captcha.restart_delay))
|
||||
|
||||
LOG.warning("############################################")
|
||||
LOG.warning("# Captcha present! Please solve the captcha.")
|
||||
LOG.warning("############################################")
|
||||
|
||||
if not is_login_page:
|
||||
await self.web_scroll_page_down()
|
||||
|
||||
input(_("Press a key to continue..."))
|
||||
except TimeoutError:
|
||||
pass
|
||||
|
||||
async def login(self) -> None:
|
||||
LOG.info("Checking if already logged in...")
|
||||
await self.web_open(f"{self.root_url}")
|
||||
@@ -503,15 +523,6 @@ class KleinanzeigenBot(WebScrapingMixin):
|
||||
LOG.info("Opening login page...")
|
||||
await self.web_open(f"{self.root_url}/m-einloggen.html?targetUrl=/")
|
||||
|
||||
try:
|
||||
await self.web_find(By.CSS_SELECTOR, "iframe[src*='captcha-delivery.com']", timeout = 2)
|
||||
LOG.warning("############################################")
|
||||
LOG.warning("# Captcha present! Please solve the captcha.")
|
||||
LOG.warning("############################################")
|
||||
await self.web_await(lambda: self.web_find(By.ID, "login-form") is not None, timeout = 5 * 60)
|
||||
except TimeoutError:
|
||||
pass
|
||||
|
||||
await self.fill_login_data_and_send()
|
||||
await self.handle_after_login_logic()
|
||||
|
||||
@@ -522,12 +533,14 @@ class KleinanzeigenBot(WebScrapingMixin):
|
||||
|
||||
async def fill_login_data_and_send(self) -> None:
|
||||
LOG.info("Logging in as [%s]...", self.config.login.username)
|
||||
await self.web_input(By.ID, "email", self.config.login.username)
|
||||
await self.web_input(By.ID, "login-email", self.config.login.username)
|
||||
|
||||
# clearing password input in case browser has stored login data set
|
||||
await self.web_input(By.ID, "password", "")
|
||||
await self.web_input(By.ID, "login-password", "")
|
||||
await self.web_input(By.ID, "login-password", self.config.login.password)
|
||||
|
||||
await self.check_and_wait_for_captcha(is_login_page = True)
|
||||
|
||||
await self.web_input(By.ID, "password", self.config.login.password)
|
||||
await self.web_click(By.CSS_SELECTOR, "form#login-form button[type='submit']")
|
||||
|
||||
async def handle_after_login_logic(self) -> None:
|
||||
@@ -779,24 +792,7 @@ class KleinanzeigenBot(WebScrapingMixin):
|
||||
#############################
|
||||
# wait for captcha
|
||||
#############################
|
||||
try:
|
||||
await self.web_find(
|
||||
By.CSS_SELECTOR,
|
||||
"iframe[name^='a-'][src^='https://www.google.com/recaptcha/api2/anchor?']",
|
||||
timeout = 2)
|
||||
|
||||
if self.config.captcha.auto_restart:
|
||||
LOG.warning("Captcha recognized - auto-restart enabled, abort run...")
|
||||
raise CaptchaEncountered(misc.parse_duration(self.config.captcha.restart_delay))
|
||||
|
||||
# Fallback: manuell
|
||||
LOG.warning("############################################")
|
||||
LOG.warning("# Captcha present! Please solve the captcha.")
|
||||
LOG.warning("############################################")
|
||||
await self.web_scroll_page_down()
|
||||
input(_("Press a key to continue..."))
|
||||
except TimeoutError:
|
||||
pass
|
||||
await self.check_and_wait_for_captcha(is_login_page = False)
|
||||
|
||||
#############################
|
||||
# submit
|
||||
|
||||
@@ -53,11 +53,15 @@ kleinanzeigen_bot/__init__.py:
|
||||
" -> found %s": "-> %s gefunden"
|
||||
"category": "Kategorie"
|
||||
|
||||
check_and_wait_for_captcha:
|
||||
"# Captcha present! Please solve the captcha.": "# Captcha vorhanden! Bitte lösen Sie das Captcha."
|
||||
"Captcha recognized - auto-restart enabled, abort run...": "Captcha erkannt - Auto-Neustart aktiviert, Durchlauf wird beendet..."
|
||||
"Press a key to continue...": "Eine Taste drücken, um fortzufahren..."
|
||||
|
||||
login:
|
||||
"Checking if already logged in...": "Überprüfe, ob bereits eingeloggt..."
|
||||
"Already logged in as [%s]. Skipping login.": "Bereits eingeloggt als [%s]. Überspringe Anmeldung."
|
||||
"Opening login page...": "Öffne Anmeldeseite..."
|
||||
"# Captcha present! Please solve the captcha.": "# Captcha vorhanden! Bitte lösen Sie das Captcha."
|
||||
|
||||
handle_after_login_logic:
|
||||
"# Device verification message detected. Please follow the instruction displayed in the Browser.": "# Nachricht zur Geräteverifizierung erkannt. Bitte den Anweisungen im Browser folgen."
|
||||
@@ -83,12 +87,9 @@ kleinanzeigen_bot/__init__.py:
|
||||
publish_ad:
|
||||
"Publishing ad '%s'...": "Veröffentliche Anzeige '%s'..."
|
||||
"Failed to set shipping attribute for type '%s'!": "Fehler beim setzen des Versandattributs für den Typ '%s'!"
|
||||
"# Captcha present! Please solve the captcha.": "# Captcha vorhanden! Bitte lösen Sie das Captcha."
|
||||
"Press a key to continue...": "Eine Taste drücken, um fortzufahren..."
|
||||
" -> SUCCESS: ad published with ID %s": " -> ERFOLG: Anzeige mit ID %s veröffentlicht"
|
||||
" -> effective ad meta:": " -> effektive Anzeigen-Metadaten:"
|
||||
"Could not set city from location": "Stadt konnte nicht aus dem Standort gesetzt werden"
|
||||
"Captcha recognized - auto-restart enabled, abort run...": "Captcha erkannt - Auto-Neustart aktiviert, Durchlauf wird beendet..."
|
||||
|
||||
__set_condition:
|
||||
"Unable to close condition dialog!": "Kann den Dialog für Artikelzustand nicht schließen!"
|
||||
|
||||
Reference in New Issue
Block a user