首页 > 代码库 > set up custom search api

set up custom search api

sign up google developer console, create project, generate API key

http://stackoverflow.com/questions/4082966/google-web-search-api-deprecated-what-now/11206266#11206266

 

Example Code: cx is custom search engine key, developer key is api key

"""Simple command-line example for Custom Search.

Command-line application that does a search.
"""

__author__ = ‘jcgregorio@google.com (Joe Gregorio)‘

import pprint

from apiclient.discovery import build


def main():
# Build a service object for interacting with the API. Visit
# the Google APIs Console <http://code.google.com/apis/console>
# to get an API key for your own application.
service = build("customsearch", "v1",
developerKey="AIzaSyAWk-vGpPYOAktOeXv-XeDTleoiBffrVlU")

res = service.cse().list(
q=‘chemical spill west virginia‘,
cx=‘008308517875943079687:j1fqrkb1_yi‘,
).execute()
pprint.pprint(res)

if __name__ == ‘__main__‘:
main()

set up custom search api