fix: eliminate duplicate search results in search_game_api function
This commit is contained in:
parent
06ea9efa02
commit
f920ff4740
@ -68,10 +68,13 @@ 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()
|
||||||
|
if title not in seen_titles: # Check for duplicates
|
||||||
|
seen_titles.add(title) # Add title to seen set
|
||||||
link = title_tag['href']
|
link = title_tag['href']
|
||||||
image_tag = game.find('img') # Find the image tag
|
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
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user