Thanks to visit codestin.com
Credit goes to github.com

Skip to content

CloudEngineHub/serpapi-python

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SerpApi Python Library & Package

serpapi python library logo

serpapi-python

This repository is the home of the soon–to–be official Python API wrapper for SerpApi. This serpapi module allows you to access search data in your Python application.

SerpApi supports Google, Google Maps, Google Shopping, Bing, Baidu, Yandex, Yahoo, eBay, App Stores, and more. Check out the documentation for a full list.

Current Status

This project is under development, and will be released to the public on PyPi soon.

Installation

To install the serpapi package, simply run the following command:

$ pip install serpapi

Please note that this package is separate from the soon–to–be legacy serpapi module, which is currently available on PyPi as google-search-results.

Usage

Let's start by searching for Coffee on Google:

>>> import serpapi
>>> s = serpapi.search(q="Coffee", engine="google", location="Austin, Texas", hl="en", gl="us")

The s variable now contains a SerpResults object, which acts just like a standard dictionary, with some convenient functions added on top.

Let's print the first result:

>>> s["organic_results"][0]["link"]
'https://en.wikipedia.org/wiki/Coffee'

Let's print the title of the first result, but in a more Pythonic way:

>>> s["organic_results"][0].get("title")
'Coffee - Wikipedia'

The SerpApi.com API Documentation contains a list of all the possible parameters that can be passed to the API.

Documentation

Documentation is available on Read the Docs.

Examples in python

Here is how to calls the APIs.

Search bing

import serpapi
import pprint
import os

client = serpapi.Client(api_key=os.getenv("API_KEY"))
data = client.search({
    'engine': 'bing',
    'q': 'coffee',
})

test: tests/example_search_bing_test.py see: serpapi.com/bing-search-api

Search baidu

import serpapi
import pprint
import os

client = serpapi.Client(api_key=os.getenv("API_KEY"))
data = client.search({
    'engine': 'baidu',
    'q': 'coffee',
})

test: tests/example_search_baidu_test.py see: serpapi.com/baidu-search-api

Search yahoo

import serpapi
import pprint
import os

client = serpapi.Client(api_key=os.getenv("API_KEY"))
data = client.search({
    'engine': 'yahoo',
    'p': 'coffee',
})

test: tests/example_search_yahoo_test.py see: serpapi.com/yahoo-search-api

Search youtube

import serpapi
import pprint
import os

client = serpapi.Client(api_key=os.getenv("API_KEY"))
data = client.search({
    'engine': 'youtube',
    'search_query': 'coffee',
})

test: tests/example_search_youtube_test.py see: serpapi.com/youtube-search-api

Search walmart

import serpapi
import pprint
import os

client = serpapi.Client(api_key=os.getenv("API_KEY"))
data = client.search({
    'engine': 'walmart',
    'query': 'coffee',
})

test: tests/example_search_walmart_test.py see: serpapi.com/walmart-search-api

Search ebay

import serpapi
import pprint
import os

client = serpapi.Client(api_key=os.getenv("API_KEY"))
data = client.search({
    'engine': 'ebay',
    '_nkw': 'coffee',
})

test: tests/example_search_ebay_test.py see: serpapi.com/ebay-search-api

Search naver

import serpapi
import pprint
import os

client = serpapi.Client(api_key=os.getenv("API_KEY"))
data = client.search({
    'engine': 'naver',
    'query': 'coffee',
})

test: tests/example_search_naver_test.py see: serpapi.com/naver-search-api

Search home depot

import serpapi
import pprint
import os

client = serpapi.Client(api_key=os.getenv("API_KEY"))
data = client.search({
    'engine': 'home_depot',
    'q': 'table',
})

test: tests/example_search_home_depot_test.py see: serpapi.com/home-depot-search-api

Search apple app store

import serpapi
import pprint
import os

client = serpapi.Client(api_key=os.getenv("API_KEY"))
data = client.search({
    'engine': 'apple_app_store',
    'term': 'coffee',
})

test: tests/example_search_apple_app_store_test.py see: serpapi.com/apple-app-store

Search duckduckgo

import serpapi
import pprint
import os

client = serpapi.Client(api_key=os.getenv("API_KEY"))
data = client.search({
    'engine': 'duckduckgo',
    'q': 'coffee',
})

test: tests/example_search_duckduckgo_test.py see: serpapi.com/duckduckgo-search-api

Search google

import serpapi
import pprint
import os

client = serpapi.Client(api_key=os.getenv("API_KEY"))
data = client.search({
    'engine': 'google',
    'q': 'coffee',
    'engine': 'google',
})

test: tests/example_search_google_test.py see: serpapi.com/search-api

Search google scholar

import serpapi
import pprint
import os

client = serpapi.Client(api_key=os.getenv("API_KEY"))
data = client.search({
    'engine': 'google_scholar',
    'q': 'coffee',
})

test: tests/example_search_google_scholar_test.py see: serpapi.com/google-scholar-api

Search google autocomplete

import serpapi
import pprint
import os

client = serpapi.Client(api_key=os.getenv("API_KEY"))
data = client.search({
    'engine': 'google_autocomplete',
    'q': 'coffee',
})

test: tests/example_search_google_autocomplete_test.py see: serpapi.com/google-autocomplete-api

Search google product

import serpapi
import pprint
import os

client = serpapi.Client(api_key=os.getenv("API_KEY"))
data = client.search({
    'engine': 'google_product',
    'q': 'coffee',
    'product_id': '4887235756540435899',
})

test: tests/example_search_google_product_test.py see: serpapi.com/google-product-api

Search google reverse image

import serpapi
import pprint
import os

client = serpapi.Client(api_key=os.getenv("API_KEY"))
data = client.search({
    'engine': 'google_reverse_image',
    'image_url': 'https://i.imgur.com/5bGzZi7.jpg',
    'max_results': '1',
})

test: tests/example_search_google_reverse_image_test.py see: serpapi.com/google-reverse-image

Search google events

import serpapi
import pprint
import os

client = serpapi.Client(api_key=os.getenv("API_KEY"))
data = client.search({
    'engine': 'google_events',
    'q': 'coffee',
})

test: tests/example_search_google_events_test.py see: serpapi.com/google-events-api

Search google local services

import serpapi
import pprint
import os

client = serpapi.Client(api_key=os.getenv("API_KEY"))
data = client.search({
    'engine': 'google_local_services',
    'q': 'electrician',
    'data_cid': '6745062158417646970',
})

test: tests/example_search_google_local_services_test.py see: serpapi.com/google-local-services-api

Search google maps

import serpapi
import pprint
import os

client = serpapi.Client(api_key=os.getenv("API_KEY"))
data = client.search({
    'engine': 'google_maps',
    'q': 'pizza',
    'll': '@40.7455096,-74.0083012,15.1z',
    'type': 'search',
})

test: tests/example_search_google_maps_test.py see: serpapi.com/google-maps-api

Search google jobs

import serpapi
import pprint
import os

client = serpapi.Client(api_key=os.getenv("API_KEY"))
data = client.search({
    'engine': 'google_jobs',
    'q': 'coffee',
})

test: tests/example_search_google_jobs_test.py see: serpapi.com/google-jobs-api

Search google play

import serpapi
import pprint
import os

client = serpapi.Client(api_key=os.getenv("API_KEY"))
data = client.search({
    'engine': 'google_play',
    'q': 'kite',
    'store': 'apps',
    'max_results': '2',
})

test: tests/example_search_google_play_test.py see: serpapi.com/google-play-api

Search google images

import serpapi
import pprint
import os

client = serpapi.Client(api_key=os.getenv("API_KEY"))
data = client.search({
    'engine': 'google_images',
    'engine': 'google_images',
    'tbm': 'isch',
    'q': 'coffee',
})

test: tests/example_search_google_images_test.py see: serpapi.com/images-results

License

MIT License.

Contributing

Bug reports and pull requests are welcome on GitHub. Once dependencies are installed, you can run the tests with pytest.

About

an official Python client library for SerpApi.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%