fix: Unable to download single ad (#509)

This commit is contained in:
Heavenfighter
2025-05-14 11:24:16 +02:00
committed by GitHub
parent 8e2385c078
commit 0faa022e4d
4 changed files with 15 additions and 36 deletions

View File

@@ -1061,7 +1061,7 @@ class KleinanzeigenBot(WebScrapingMixin):
# call download function for each ad page
for add_url in own_ad_urls:
ad_id = ad_extractor.extract_ad_id_from_ad_url(add_url)
if await ad_extractor.naviagte_to_ad_page(add_url):
if await ad_extractor.navigate_to_ad_page(add_url):
await ad_extractor.download_ad(ad_id)
success_count += 1
LOG.info("%d of %d ads were downloaded from your profile.", success_count, len(own_ad_urls))
@@ -1085,7 +1085,7 @@ class KleinanzeigenBot(WebScrapingMixin):
LOG.info("The ad with id %d has already been saved.", ad_id)
continue
if await ad_extractor.naviagte_to_ad_page(ad_url):
if await ad_extractor.navigate_to_ad_page(ad_url):
await ad_extractor.download_ad(ad_id)
new_count += 1
LOG.info("%s were downloaded from your profile.", pluralize("new ad", new_count))
@@ -1096,7 +1096,7 @@ class KleinanzeigenBot(WebScrapingMixin):
LOG.info(" | ".join([str(ad_id) for ad_id in ids]))
for ad_id in ids: # call download routine for every id
exists = await ad_extractor.naviagte_to_ad_page(ad_id)
exists = await ad_extractor.navigate_to_ad_page(ad_id)
if exists:
await ad_extractor.download_ad(ad_id)
LOG.info("Downloaded ad with id %d", ad_id)

View File

@@ -8,7 +8,7 @@ from typing import Any, Final
from .ads import calculate_content_hash, get_description_affixes
from .utils import dicts, i18n, loggers, misc, reflect
from .utils.web_scraping_mixin import Browser, By, Element, Is, WebScrapingMixin
from .utils.web_scraping_mixin import Browser, By, Element, WebScrapingMixin
__all__ = [
"AdExtractor",
@@ -239,20 +239,14 @@ class AdExtractor(WebScrapingMixin):
return refs
async def naviagte_to_ad_page(self, id_or_url:int | str) -> bool:
async def navigate_to_ad_page(self, id_or_url: int | str) -> bool:
"""
Navigates to an ad page specified with an ad ID; or alternatively by a given URL.
:return: whether the navigation to the ad page was successful
"""
if reflect.is_integer(id_or_url):
# navigate to start page, otherwise page can be None!
await self.web_open("https://www.kleinanzeigen.de/")
# enter the ad ID into the search bar
await self.web_input(By.ID, "site-search-query", id_or_url)
# navigate to ad page and wait
await self.web_check(By.ID, "site-search-submit", Is.CLICKABLE)
submit_button = await self.web_find(By.ID, "site-search-submit")
await submit_button.click()
# navigate to search page
await self.web_open("https://www.kleinanzeigen.de/s-suchanfrage.html?keywords={0}".format(id_or_url))
else:
await self.web_open(str(id_or_url)) # navigate to URL directly given
await self.web_sleep()

View File

@@ -184,7 +184,7 @@ kleinanzeigen_bot/extract.py:
"Found %s ad items on page %s.": "%s Anzeigen-Elemente auf Seite %s gefunden."
"Successfully extracted %s refs from page %s.": "%s Referenzen von Seite %s erfolgreich extrahiert."
naviagte_to_ad_page:
navigate_to_ad_page:
"There is no ad under the given ID.": "Es gibt keine Anzeige unter der angegebenen ID."
"A popup appeared!": "Ein Popup ist erschienen!"