import requests from bs4 import BeautifulSoup def search_game(search_term): url = "https://www.switchscores.com/games/search" params = { '_token': 'UioRaADSoKqKdebnI66WRqBwtgqqte79sEMm0tVK', 'search_keywords': search_term } response = requests.get(url, params=params) if response.status_code == 200: soup = BeautifulSoup(response.text, 'html.parser') results = soup.select('.row > .col-sm-12') # Using CSS selector based on the provided HTML structure count = 0 # Initialize the counter for found results seen_titles = set() # Set to track seen titles to avoid duplicates for game in results: title_tag = game.find('span', class_='h5').find('a') if game.find('span', class_='h5') else None if title_tag: # Only output if a title is found title = title_tag.text.strip() if title not in seen_titles: # Check if the title has already been seen seen_titles.add(title) # Add title to the set of seen titles link = title_tag['href'] image_tag = game.find('img') # Find the image tag image_link = image_tag['src'] if image_tag and 'src' in image_tag.attrs else "Kein Bild gefunden" # Get the image link if it exists if image_link != "Kein Bild gefunden": image_link = f"https://www.switchscores.com{image_link}" # Prefix the image link release_date = game.find('span', class_='h6').text.strip() if game.find('span', class_='h6') else "Kein Veröffentlichungsdatum gefunden" price = game.find('span', class_='h4').text.strip() if game.find('span', class_='h4') else "Kein Preis gefunden" rating = game.find('span', class_='switch-rating-badge').text.strip() if game.find('span', class_='switch-rating-badge') else "Keine Bewertung gefunden" print(f"Titel: {title}\nLink: {link}\nBildlink: {image_link}\nVeröffentlichungsdatum: {release_date}\nPreis: {price}\nBewertung: {rating}\n") count += 1 # Increment the counter for each found title print(f"Anzahl der gefundenen Ergebnisse: {count}") # Output the count of found results else: print("Fehler beim Abrufen der Seite.") if __name__ == '__main__': search_term = input("Bitte geben Sie ein Suchwort ein: ") search_game(search_term)