From 8d6524e086432a0884c16ffb71e8da13aec1ca96 Mon Sep 17 00:00:00 2001 From: KeksNino Date: Tue, 17 Dec 2024 16:56:10 +0100 Subject: [PATCH] added search function to scraper --- scraper.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/scraper.py b/scraper.py index 4efb16c..4c6ff37 100644 --- a/scraper.py +++ b/scraper.py @@ -19,14 +19,31 @@ if response.status_code == 200: continue games = soup.find_all("li") - if games: + game_titles = [game.text.strip() for game in games] + + if game_titles: print("Games Found:") - for game in games: - print(game.text.strip()) + for title in game_titles: + pass else: print("No game titles found. Report this on Github.") else: print(f"Failed to retrieve the page. Status code: {response.status_code}") + +def search_games(query, game_titles): + results = [title for title in game_titles if query.lower() in title.lower()] + return results + +search_query = input("Enter a game title to search: ") +search_results = search_games(search_query, game_titles) + +if search_results: + print("Search Results:") + for result in search_results: + print(result) +else: + print("No matching game titles found.") + # url = "https://cs.rin.ru/" # url = "https://gamesdrive.net/" # url = "https://gog-games.to/" @@ -51,7 +68,7 @@ else: # url = "https://www.cg-gamespc.com/" # url = "https://gamepcfull.com/" -# # Repacks/Torrents +# Repacks/Torrents # url = "https://www.kaoskrew.org/" # url = "https://fitgirl-repacks.site/" # url = "https://m4ckd0ge-repacks.site/"