Perform Google Search using Python
Introduction:
In the era of information technology
Python and GoogleSearch:
Python, with its extensive libraries and tools
Let's dive into the code:
from googlesearch import search
def get_user_query():
return input("What do you want to search on Google? ")
def google_search(query):
top_results = list(search(query, num_results=5))
print(f"\nTop 5 results for '{query}':\n")
for idx, result in enumerate(top_results, start=1):
print(f"{idx}. {result}")
if __name__ == "__main__":
user_query = get_user_query()
google_search(user_query)
Explanation of the Code:
Recommended by LinkedIn
Conclusion:
In this blog, we explored a simple Python script that enables us to perform a Google search and fetch the top 5 results based on a user-specified query. Python's vast ecosystem of libraries empowers developers to interact with the web in various ways, making it an ideal language for web scraping, data retrieval, and more.
With a little creativity and some additional programming, you can extend this simple Google search tool to suit your specific needs.