Introduction
In this blog post, you will be guided with the simplest method on how to perform the programmatic Google search using the open source python packages.
The following is the code snippet which demonstrates the usage of the most prominent packages for accomplishing the real-time Google search.
!python3 -m pip install googlesearch-python
Hands-on
Let's get our hands dirty in working and solving the real problem. We need to search query to start with. Let us consider the following.
search_query = 'Sea food near Googleplex\n1600 Amphitheatre Parkway\nMountain View, CA 94043\nUnited States'
Let's do the real time google search using the following code. We could also limit the number of interested results.
google_search_results = []
number_of_results = 2
from googlesearch import search
results = search(search_query, lang="en", num_results=number_of_results)
Let's do some more results formatting to eliminate the unwanted results.
for result in results:
if not result.startswith("https://www.tripadvisor.com"):
google_search_results.append(result)
Coming Next
Please refer to the below blog posts to perform the data extraction including the structured data extract using Google Gemini Pro LLM.
google-search-with-structured-data-extraction
web-scraping-with-langchain-and-html2text
Top comments (0)