cuery.seo.aio.hasdata#
HasData AI Overview async helpers.
Functions#
|
Normalize whitespace inside extracted snippets. |
|
Yield bullet-point lines from a (possibly nested) list block structure. |
|
|
|
|
|
Parse HasData |
|
Check if we need to make a second request to get the actual AI overview. |
|
Asynchronously execute a Google search via HasData and extract AI Overview. |
|
Create zero-argument coroutine factories (with policies) for many prompts. |
Module Contents#
- cuery.seo.aio.hasdata._clean_text(text)#
Normalize whitespace inside extracted snippets.
Collapses multiple spaces, trims each line and removes trailing spaces while preserving single newlines. Empty lines are kept only once.
- Parameters:
text (str)
- Return type:
str
- cuery.seo.aio.hasdata._iter_list_items(items, indent=0)#
Yield bullet-point lines from a (possibly nested) list block structure.
- Parameters:
items (collections.abc.Iterable[dict])
indent (int)
- Return type:
collections.abc.Iterable[str]
- cuery.seo.aio.hasdata._format_table(block)#
- Parameters:
block (dict)
- Return type:
str
- cuery.seo.aio.hasdata._format_code(block)#
- Parameters:
block (dict)
- Return type:
str
- cuery.seo.aio.hasdata.parse_aio(aio)#
Parse HasData
aiOverviewobject into a unifiedSearchResult.Documentation: https://docs.hasdata.com/apis/google-serp-api/rich-snippets/ai-overview
We concatenate textual content from the following block types in order: paragraph, list (including nested lists), table, code, video (snippet), carousel (ignored – mostly images). Unknown types are skipped silently to remain forward-compatible.
Lists are flattened into bullet points. Tables become pipe-delimited lines with the first row treated as a header. Code blocks are prefixed with a
[Code:<lang>]marker. Whitespace is normalized and excessive blank lines removed.- Parameters:
aio (dict)
- Return type:
- cuery.seo.aio.hasdata.aio_request_params(aio)#
Check if we need to make a second request to get the actual AI overview.
- Parameters:
aio (dict)
- Return type:
dict | None
- async cuery.seo.aio.hasdata.query(prompt, country=None, language=None, validate=True, log=False, session=None)#
Asynchronously execute a Google search via HasData and extract AI Overview.
- Parameters:
prompt (str) – Query string.
country (str | None) – Optional 2-letter country code (gl param).
language (str | None) – Optional 2-letter language code (hl param).
validate (bool) – If True return parsed
SearchResult, else raw dict.log (bool) – If True, log request/response bodies.
session (aiohttp.ClientSession | None) – Optional existing
aiohttp.ClientSessionto reuse. If not provided a temporary session is created and closed.
- Return type:
cuery.search.SearchResult | dict[str, Any]
- async cuery.seo.aio.hasdata.gather(prompts, country=None, language=None, validate=True, log=False, session=None, policies=None, execute=True)#
Create zero-argument coroutine factories (with policies) for many prompts.
- Parameters:
prompts (collections.abc.Sequence[str] | collections.abc.Iterable[str])
country (str | None)
language (str | None)
validate (bool)
log (bool)
session (aiohttp.ClientSession | None)
policies (dict[str, Any] | None)
execute (bool)
- Return type:
list[collections.abc.Coroutine] | list[cuery.search.SearchResult | dict[str, Any]]