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
|
results = soup.select('.row > .col-sm-12') # Using CSS selector based on the provided HTML structure
|
||||||
|
|
||||||
games_list = [] # List to hold found games
|
games_list = [] # List to hold found games
|
||||||
|
seen_titles = set() # Set to track seen titles to avoid duplicates
|
||||||
for game in results:
|
for game in results:
|
||||||
title_tag = game.find('span', class_='h5').find('a') if game.find('span', class_='h5') else None
|
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
|
if title_tag: # Only output if a title is found
|
||||||
title = title_tag.text.strip()
|
title = title_tag.text.strip()
|
||||||
link = title_tag['href']
|
if title not in seen_titles: # Check for duplicates
|
||||||
image_tag = game.find('img') # Find the image tag
|
seen_titles.add(title) # Add title to seen set
|
||||||
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
|
link = title_tag['href']
|
||||||
if image_link != "Kein Bild gefunden":
|
image_tag = game.find('img') # Find the image tag
|
||||||
image_link = f"https://www.switchscores.com{image_link}" # Prefix the image link
|
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
|
||||||
release_date = game.find('span', class_='h6').text.strip() if game.find('span', class_='h6') else "Kein Veröffentlichungsdatum gefunden"
|
if image_link != "Kein Bild gefunden":
|
||||||
price = game.find('span', class_='h4').text.strip() if game.find('span', class_='h4') else "Kein Preis gefunden"
|
image_link = f"https://www.switchscores.com{image_link}" # Prefix the image link
|
||||||
rating = game.find('span', class_='switch-rating-badge').text.strip() if game.find('span', class_='switch-rating-badge') else "Keine Bewertung gefunden"
|
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"
|
||||||
games_list.append({
|
rating = game.find('span', class_='switch-rating-badge').text.strip() if game.find('span', class_='switch-rating-badge') else "Keine Bewertung gefunden"
|
||||||
'title': title,
|
|
||||||
'link': link,
|
games_list.append({
|
||||||
'image_link': image_link,
|
'title': title,
|
||||||
'release_date': release_date,
|
'link': link,
|
||||||
'price': price,
|
'image_link': image_link,
|
||||||
'rating': rating
|
'release_date': release_date,
|
||||||
})
|
'price': price,
|
||||||
|
'rating': rating
|
||||||
|
})
|
||||||
|
|
||||||
return jsonify(games_list), 200 # Return the list of games found
|
return jsonify(games_list), 200 # Return the list of games found
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user