[go: up one dir, main page]

DEV Community

Cover image for Realtime Google Search
Ranjan Dailata
Ranjan Dailata

Posted on

Realtime Google Search

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
Enter fullscreen mode Exit fullscreen mode

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'
Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode

Realtime-Google-Search

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)