Here we will search on google through python and display top 5links in our terminal.
Aug 3, 2023
As always i will be explaining in comments
import googlesearch #we use googlesearch library
def google_search(query, num_results=5):
search_results = googlesearch.search(query, stop=num_results, pause=2.0)
return search_results #returning search_results to use in main method
if __name__ == "__main__":
search_query = input("Enter What You Want To Search for")
top_5_results = google_search(search_query)
print(f"Top 5 results for '{search_query}':")
for i, result in enumerate(top_5_results, 1):
print(f"{i}. {result}") #through the help of for loop we print the top 5 results