Continuous Test Orchestration And Execution Platform Online

Perform automated and live-interactive testing on 3000+ real desktop and mobile devices online.

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"])
LambdaTest

Test your websites, web-apps, or mobile apps seamlessly with LambdaTest.

Start Free Testing
LambdaTest

Earn resume-worthy Selenium certifications that help you land a top job.

Learn More
LambdaTest

Test your web or mobile apps

Test orchestration and execution cloud of 3000+ browsers and OS

Support

24/7 support

Security

Enterprise grade security

Cloud

Fastest test execution cloud