python Google Custom Search API

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python Google Custom Search API相关的知识,希望对你有一定的参考价值。

from googleapiclient.discovery import build
import pprint

my_api_key = "Google API key"
my_cse_id = "Custom Search Engine ID"

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('query string', my_api_key, my_cse_id, num=10)
for result in results:
    pprint.pprint(result)

以上是关于python Google Custom Search API的主要内容,如果未能解决你的问题,请参考以下文章