scrape_fotograf.py aktualisiert
This commit is contained in:
@@ -8,7 +8,7 @@ from selenium.webdriver.chrome.options import Options
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.support.ui import WebDriverWait
|
||||
from selenium.webdriver.support import expected_conditions as EC
|
||||
from selenium.common.exceptions import TimeoutException, NoSuchElementException, InvalidSelectorException
|
||||
from selenium.common.exceptions import TimeoutException, NoSuchElementException
|
||||
|
||||
# --- Konfiguration & Konstanten ---
|
||||
CREDENTIALS_FILE = 'fotograf_credentials.json'
|
||||
@@ -16,24 +16,27 @@ OUTPUT_DIR = 'output'
|
||||
OUTPUT_FILE = os.path.join(OUTPUT_DIR, 'nutzer_ohne_logins.csv')
|
||||
LOGIN_URL = 'https://app.fotograf.de/login/login'
|
||||
|
||||
# --- Selektoren (FINALE VERSION 2.0) ---
|
||||
# --- Selektoren (FINALE VERSION 3.0) ---
|
||||
SELECTORS = {
|
||||
"cookie_accept_button": "#CybotCookiebotDialogBodyLevelButtonLevelOptinAllowAll",
|
||||
"login_user": "#login-email",
|
||||
"login_pass": "#login-password",
|
||||
"login_button": "#login-submit",
|
||||
"job_name": "h1",
|
||||
# Album-Übersicht (funktioniert)
|
||||
# Album-Übersicht
|
||||
"album_overview_rows": "//table/tbody/tr",
|
||||
"album_overview_link": ".//td[2]//a",
|
||||
|
||||
# Einzelpersonen-Ansicht (basierend auf Ihrem finalen HTML)
|
||||
# Einzelpersonen-Ansicht (innerhalb eines Albums)
|
||||
"person_rows": "//div[contains(@class, 'border-legacy-silver-550') and .//span[text()='Logins']]",
|
||||
"person_vorname": ".//span[text()='Vorname']/following-sibling::strong",
|
||||
"person_logins": ".//span[text()='Logins']/following-sibling::strong",
|
||||
"person_buyer_link": ".//a[contains(@data-qa-id, 'guest-access-banner-access-code')]",
|
||||
"person_access_code_link": ".//a[contains(@data-qa-id, 'guest-access-banner-access-code')]",
|
||||
|
||||
# Käufer-Detailseite (funktioniert)
|
||||
# "Kommunikation"-Seite (nach Klick auf Zugangscode)
|
||||
"potential_buyer_link": "//a[contains(@href, '/config_customers/view_customer')]",
|
||||
|
||||
# Käufer-Detailseite (finale Seite)
|
||||
"buyer_email": "//span[contains(., '@')]"
|
||||
}
|
||||
|
||||
@@ -77,8 +80,7 @@ def login(driver, username, password):
|
||||
wait = WebDriverWait(driver, 10)
|
||||
try:
|
||||
print("Suche nach Cookie-Banner...")
|
||||
cookie_button = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, SELECTORS["cookie_accept_button"])))
|
||||
cookie_button.click()
|
||||
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, SELECTORS["cookie_accept_button"]))).click()
|
||||
print("Cookie-Banner akzeptiert.")
|
||||
time.sleep(1)
|
||||
except TimeoutException:
|
||||
@@ -121,9 +123,8 @@ def process_full_job(driver, job_url):
|
||||
print(f"{len(album_rows)} Alben in der Übersicht gefunden.")
|
||||
for row in album_rows:
|
||||
try:
|
||||
album_name = row.find_element(By.XPATH, SELECTORS["album_overview_link"]).text
|
||||
album_link = row.find_element(By.XPATH, SELECTORS["album_overview_link"]).get_attribute('href')
|
||||
albums_to_visit.append({"name": album_name, "url": album_link})
|
||||
album_link = row.find_element(By.XPATH, SELECTORS["album_overview_link"])
|
||||
albums_to_visit.append({"name": album_link.text, "url": album_link.get_attribute('href')})
|
||||
except NoSuchElementException:
|
||||
continue
|
||||
print(f"{len(albums_to_visit)} gültige Album-Links gesammelt.")
|
||||
@@ -137,26 +138,26 @@ def process_full_job(driver, job_url):
|
||||
print(f"\n--- Betrete Album: {album['name']} ---")
|
||||
driver.get(album['url'])
|
||||
try:
|
||||
# Warten, bis die Personen-DIVs geladen sind
|
||||
person_rows = wait.until(EC.presence_of_all_elements_located((By.XPATH, SELECTORS["person_rows"])))
|
||||
print(f"{len(person_rows)} Personen in diesem Album gefunden.")
|
||||
|
||||
for person_row in person_rows:
|
||||
try:
|
||||
login_count_text = person_row.find_element(By.XPATH, SELECTORS["person_logins"]).text
|
||||
login_count = int(login_count_text)
|
||||
|
||||
login_count = int(person_row.find_element(By.XPATH, SELECTORS["person_logins"]).text)
|
||||
if login_count == 0:
|
||||
vorname = person_row.find_element(By.XPATH, SELECTORS["person_vorname"]).text
|
||||
print(f" --> ERFOLG: '{vorname}' mit 0 Logins gefunden!")
|
||||
|
||||
buyer_link_element = person_row.find_element(By.XPATH, SELECTORS["person_buyer_link"])
|
||||
buyer_page_url = buyer_link_element.get_attribute('href')
|
||||
|
||||
# E-Mail in einem neuen Tab holen, um den Kontext nicht zu verlieren
|
||||
driver.execute_script("window.open(arguments[0]);", buyer_page_url)
|
||||
driver.switch_to.window(driver.window_handles[-1])
|
||||
# 1. Gehe zur "Kommunikation"-Seite
|
||||
access_code_page_url = person_row.find_element(By.XPATH, SELECTORS["person_access_code_link"]).get_attribute('href')
|
||||
driver.get(access_code_page_url)
|
||||
print(f" Navigiere zur Kommunikations-Seite für '{vorname}'...")
|
||||
|
||||
# 2. Klicke auf den Link zum potenziellen Käufer, um zur finalen Seite zu gelangen
|
||||
wait.until(EC.element_to_be_clickable((By.XPATH, SELECTORS["potential_buyer_link"]))).click()
|
||||
print(f" Navigiere zur Käufer-Detailseite...")
|
||||
|
||||
# 3. Extrahiere die E-Mail
|
||||
email = wait.until(EC.visibility_of_element_located((By.XPATH, SELECTORS["buyer_email"]))).text
|
||||
print(f" E-Mail gefunden: {email}")
|
||||
|
||||
@@ -167,10 +168,10 @@ def process_full_job(driver, job_url):
|
||||
"Käufer E-Mail": email
|
||||
})
|
||||
|
||||
driver.close()
|
||||
driver.switch_to.window(driver.window_handles[0])
|
||||
|
||||
except (ValueError, NoSuchElementException):
|
||||
# Gehe zurück zur Album-Detailseite, um die nächste Person zu prüfen
|
||||
driver.get(album['url'])
|
||||
except (ValueError, NoSuchElementException, TimeoutException) as e:
|
||||
#print(f" Fehler beim Verarbeiten einer Person: {e}")
|
||||
continue
|
||||
except TimeoutException:
|
||||
print(f" Keine Personen-Daten im Album '{album['name']}' gefunden. Überspringe.")
|
||||
@@ -193,6 +194,7 @@ def save_results_to_csv(results):
|
||||
print("Speichern erfolgreich!")
|
||||
|
||||
def get_profile_choice():
|
||||
# ... unverändert ...
|
||||
all_credentials = load_all_credentials()
|
||||
if not all_credentials: return None
|
||||
profiles = list(all_credentials.keys())
|
||||
@@ -209,6 +211,7 @@ def get_profile_choice():
|
||||
except ValueError: print("Ungültige Eingabe.")
|
||||
|
||||
def main():
|
||||
# ... unverändert ...
|
||||
print("--- Fotograf.de Scraper für Nutzer ohne Logins (FINALE VERSION) ---")
|
||||
credentials = get_profile_choice()
|
||||
if not credentials: return
|
||||
|
||||
Reference in New Issue
Block a user