fix: eliminate duplicate search results in search_game_api function
This commit is contained in:
parent
06ea9efa02
commit
f920ff4740
@ -68,27 +68,30 @@ def search_game_api():
|
||||
results = soup.select('.row > .col-sm-12') # Using CSS selector based on the provided HTML structure
|
||||
|
||||
games_list = [] # List to hold found games
|
||||
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()
|
||||
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"
|
||||
if title not in seen_titles: # Check for duplicates
|
||||
seen_titles.add(title) # Add title to seen set
|
||||
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"
|
||||
|
||||
games_list.append({
|
||||
'title': title,
|
||||
'link': link,
|
||||
'image_link': image_link,
|
||||
'release_date': release_date,
|
||||
'price': price,
|
||||
'rating': rating
|
||||
})
|
||||
games_list.append({
|
||||
'title': title,
|
||||
'link': link,
|
||||
'image_link': image_link,
|
||||
'release_date': release_date,
|
||||
'price': price,
|
||||
'rating': rating
|
||||
})
|
||||
|
||||
return jsonify(games_list), 200 # Return the list of games found
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user