Next-Gen App & Browser
Testing Cloud

Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles

Next-Gen App & Browser Testing Cloud

How to Get Google Search Results in Python?

Here are steps to follow to get Google search results in Python:

  • Get a Google API key by signing up for the service (free version).
  • Find Google Custom Search now, then register for a free account to receive a custom search id.
  • Add the Google API Python Client package to your Python project by typing:
  • !pip instal google-api-python-client

Now all you have to do is execute the following code:

from googleapiclient.discovery import build


my_api_key = "your API KEY TYPE HERE"
my_cse_id = "YOUR CUSTOM SEARCH ENGINE ID TYPE HERE"


def google_search(search_term, api_key, cse_id, **kwargs):
      service = build("customsearch", "v1", developerKey=api_key)
      res = service.cse().list(q=search_term, cx=cse_id, **kwargs).execute()
      return res['items']


results= google_search("YOUR SEARCH QUERY HERE",my_api_key,my_cse_id,num=10)


for result in results:
      print(result["link"])

Test your website on 3000+ browsers

Get 100 minutes of automation test minutes FREE!!

Test Now...

KaneAI - Testing Assistant

World’s first AI-Native E2E testing agent.

...
ShadowLT Logo

Start your journey with LambdaTest

Get 100 minutes of automation test minutes FREE!!

Signup for free