Welcome to google-custom-search’s documentation!#
This is api library.
Quick start#
install#
pip install google-custom-search
or if you use async version, please run this.
pip install google-custom-search[async]
sample#
sync#
import google_custom_search
google = google_custom_search.CustomSearch(apikey="your api_key", engine_id="your engine_id")
# if image is True, it's can search, but you need to setting at google console search
results = google.search("Hello")
for result in results:
# get a kind
print(result.kind)
# get a title.
print(result.title)
# get a link.
print(result.url)
# get a displayLink.
print(result.display_url)
# get a htmlTitle.
print(result.html_title)
# get a snippet.
print(result.snippet)
async#
import asyncio
import google_custom_search
google = google_custom_search.CustomSearch(token="your api_key", engine_id="your engine_id", image=True)
# if image is True, it's can search, but you need to setting at google console search
async def main():
results = await google.search_async("word!")
for result in results:
# get a kind
print(result.kind)
# get a title.
print(result.title)
# get a link.
print(result.url)
# get a displayLink.
print(result.display_url)
# get a htmlTitle.
print(result.html_title)
# get a snippet.
print(result.snippet)
asyncio.run(main())
google-custom-search library#
Submodules#
google_custom_search.search module#
- class google_custom_search.search.CustomSearch(apikey: str, engine_id: str, image: Optional[bool] = False)#
Bases:
object
This is the class used when using Google Custom Search.
- Parameters
apikey (str) – Insert google custom search api key.
engine_id (str) – Insert google custom search engine id.
- APIURL = 'https://www.googleapis.com/customsearch/v1'#
- search(keyword: str) List[Item] #
This is searched using api.
- Parameters
keyword (str) – Search word
- Returns
return result
- Return type
List[Item]
- Raises
ApiNotEnabled – api is not invalid
- async search_async(keyword: str) List[Item] #
This is an asynchronous version of custom_search.search.
- Parameters
keyword (str) – Search word
- Returns
return result
- Return type
List[Item]
- Raises
ApiNotEnabled – api is not invalid
AsyncError – If you don’t install aiohttp, lib call error.
Note
You need aiohttp library.
google_custom_search.types module#
- class google_custom_search.types.Item(data: dict)#
Bases:
object
This is return a item.
- property display_url: str#
This is the display url of the item.
- property html_title: str#
This is the html title of the item.
- property kind: str#
This is the kind of the item.
- property snippet: str#
This is the snippet of the item.
- property title: str#
This is the title of the item.
- property url: str#
This is the url of the item.
google_custom_search.errors module#
- exception google_custom_search.errors.ApiNotEnabled(code: str, error: str)#
Bases:
Exception
- exception google_custom_search.errors.AsyncError#
Bases:
Exception