AI 概览
了解如何使用 Web Scraper API 提取 AI 概览。查找代码示例和支持的参数。
该 google_search 和 google_ads 来源可以在所有支持的全球地区从 Google 搜索结果返回 Google AI 概述。 ai_overviews 结果数组在单个响应中支持多个 AI 块,包括“大家也在问”和“需要了解的事项”等部分。
为最大化收到完全呈现的 AI 概述内容的机会,您必须包含以下参数:
source
google_search 或 google_ads
render
html
user_agent_type
desktop 或 mobile
使用这些参数还可以使您通过单个请求同时接收通用响应和 AI 概述内容。
Google 会动态生成此内容或加载缓存版本,因此 AI 生成的答案可能随时间变化,即使参数相同。
探索 数据字典 以了解部分 AI 概述 SERP 功能。
AI 概述地区可用性
Google AI 概述在大多数国家可用,但有一些例外。目前最大的排除国家包括:
法国
中国
伊朗
朝鲜
Google AI 概述功能正在持续推出,随时间会包含更多国家。
请求示例
curl 'https://realtime.oxylabs.io/v1/queries' \
--user 'USERNAME:PASSWORD' \
-H 'Content-Type: application/json' \
-d '{
"source": "google_search",
"query": "how to sell on amazon",
"render": "html",
"user_agent_type": "desktop",
"parse": true
}'import requests
from pprint import pprint
# 已更新的载荷。
payload = {
'source': 'google_search',
'query': 'how to sell on amazon',
'render': 'html',
'user_agent_type': 'desktop',
}
# 获取响应。
response = requests.request(
'POST',
'https://realtime.oxylabs.io/v1/queries',
auth=('user', 'pass1'),
json=payload,
)
# 将美化后的响应打印到标准输出。
pprint(response.json())<?php
$params = [
'source' => 'google_search',
'query' => 'how to sell on amazon',
'render' => 'html',
'user_agent_type' => 'desktop',
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://realtime.oxylabs.io/v1/queries");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERPWD, "user" . ":" . "pass1");
$headers = [];
$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
echo $result;
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);https://realtime.oxylabs.io/v1/queries?source=google_search&query=Emporio%20Armani%20EA3192&render=html&user_agent_type=desktop&access_token=12345abcde{
"source": "google_search",
"query": "how to sell on amazon",
"render": "html",
"user_agent_type": "desktop"
}我们在示例中使用同步的 Realtime 集成方法。如果您想使用 Proxy Endpoint 或异步的 Push-Pull 集成,请参考 集成方法 部分。
请求参数值
通用
用于使用 AI 概述抓取 Google 网络搜索结果的基本设置和自定义选项。
- 必填参数
Google 高级搜索操作符
在抓取时,您可能会发现将 Google 高级搜索操作符与查询结合使用很有用。它使您能够定制搜索范围,确保结果更相关、更集中。在此处探索这些特殊命令 此处 和 此处。看下面的示例查询。
{
"source": "google_search",
"query": "iphone 15 launch inurl:apple",
"render": "html",
"user_agent_type": "desktop"
}本地化
将搜索结果适配到特定的地理位置、域和语言。
分页
用于管理分页和检索搜索结果的控件。
start_page
起始页码。
1
pages
要检索的页数。
1
limit
每页要检索的结果数。
10
context:limit_per_page
使用相同 IP 地址和会话(cookie 集)抓取多页。通过在带有 page 键的 JSON 数组中指定页码并使用 limit 键指明每页的自然结果数量,您可以最大限度地减少跨页出现重复自然结果的几率(例如,第一页的最后一个自然结果与第二页的第一个自然结果相同)。 参见示例.
-
支持连续滚动
Web 爬虫 API 完全支持 Google 搜索的连续滚动。它会自动检测连续滚动布局,高效加载请求的自然结果,无需任何额外参数。
每页限制
由于 Google 最近的限制更改,我们已调整 Web 爬虫 API 的行为。每页最大结果数将与 Google 的自然输出匹配,通常为 10 个结果。
要使用此功能,请包含一个 JSON 数组,该数组包含具有以下数据的 JSON 对象:
page
您想抓取的页面编号。任何大于 0 的整数值均可用
1
limit
该页上的结果数。任何在 1 和 100 (含)之间的整数值均可用。
90
请求示例
{
"source": "google_search",
"query": "how to sell on amazon",
"render": "html",
"user_agent_type": "dekstop",
"parse": true,
"context": [
{
"key": "limit_per_page",
"value": [
{"page": 1, "limit": 10},
{"page": 2, "limit": 90}
]
}]
}过滤
用于根据各种条件过滤和精炼搜索结果的选项。了解如何使用上下文参数 此处.
context:
filter
将此参数的值设置为 0 可让您查看因与其他结果相似而被排除的结果。
1
context:
safe_search
安全搜索。设置为 true 以启用它。
false
context:
tbm
待匹配或 tbm 参数。接受的值包括: app, blg, bks, dsc, isch, nws, pts, plcs, rcp, lcl
-
context:
tbs
此参数类似于用于更晦涩的 Google 参数的容器,例如按日期限制/排序结果以及其他某些依赖于 tbm 参数的过滤器(例如 tbs=app_os:1 仅在与 tbm value app一起使用时可用)。更多信息 此处.
-
udm 和 tbm 上下文参数不能在单个抓取请求中同时使用;请仅选择一个。同时使用两者可能导致冲突或意外行为。
其他
用于特殊需求的额外高级设置和控件。
context:
fpstate
将 fpstate 值设置为 aig 将使 Google 加载更多应用。该参数仅在与 render 参数一起使用时有用。
-
context:
nfpr
true 将关闭拼写自动更正
false
上下文参数
所有上下文参数应作为对象添加到 context 数组中,形式为带有 键 和 value 对,例如:
...
"context": [
{
"key": "filter",
"value": "0"
}
]
...数据结构和处理
数据字典
AI 概述 SERP 功能中所有可用键在下表中定义:
answer_text
关于 Google 搜索查询词的一般信息。
array
bullet_list
表示在 AI 概述 SERP 功能中以项目符号列表呈现的项目的信息。
array
products
包含各自详细信息的产品列表。
object
source_panel
用于生成 Google SERP 中 AI 概述结果的来源列表。
object
additional_questions
包含各自详细信息的补充问题列表。
object
recipes
包含各自详细信息的食谱列表。
object
info_list
用于表示与搜索查询相关的过程步骤的最常用信息列表。
array
pos_overall
表示 AI 概述 SERP 功能结果在所有 Google SERP 可用结果中的位置。
integer
处理多个 AI 概述
由于 AI 概述现在作为数组返回,您必须遍历它们:
// 处理响应中的所有 AI 概述
response.results.ai_overviews.forEach((aiOverview, index) => {
console.log(`Processing AI Overview #${index + 1}`);
// 处理各个组件
if (aiOverview.answer_text) {
// 处理答案文本
}
if (aiOverview.bullet_list) {
// 处理项目符号列表
}
// 等等...
});# 处理响应中的所有 AI 概述
for index, ai_overview in enumerate(response['results']['ai_overviews']):
print(f"Processing AI Overview #{index + 1}")
# 处理各个组件
if 'answer_text' in ai_overview:
answer_texts = ai_overview['answer_text']
for answer in answer_texts:
# 处理每个答案文本
if 'text' in answer:
for text_item in answer['text']:
print(f"Answer text: {text_item}")
if 'bullet_list' in ai_overview:
bullet_lists = ai_overview['bullet_list']
for bullet_list in bullet_lists:
if 'list_title' in bullet_list:
print(f"List title: {bullet_list['list_title']}")
if 'points' in bullet_list:
for point in bullet_list['points']:
print(f"- {point}")
# 继续处理其他元素...<?php
// 处理响应中的所有 AI 概述
if (isset($response['results']['ai_overviews']) && is_array($response['results']['ai_overviews'])) {
foreach ($response['results']['ai_overviews'] as $index => $aiOverview) {
$indexNumber = $index + 1;
echo "Processing AI Overview #{$indexNumber}\n";
// 处理答案文本
if (isset($aiOverview['answer_text']) && is_array($aiOverview['answer_text'])) {
foreach ($aiOverview['answer_text'] as $answer) {
if (isset($answer['text']) && is_array($answer['text'])) {
foreach ($answer['text'] as $textItem) {
echo "Answer text: {$textItem}\n";
}
}
}
}
// 处理项目符号列表
if (isset($aiOverview['bullet_list']) && is_array($aiOverview['bullet_list'])) {
foreach ($aiOverview['bullet_list'] as $bulletList) {
if (isset($bulletList['list_title'])) {
echo "List title: {$bulletList['list_title']}\n";
}
if (isset($bulletList['points']) && is_array($bulletList['points'])) {
foreach ($bulletList['points'] as $point) {
echo "- {$point}\n";
}
}
}
}
// 继续处理其他元素...
}
}
?>在大多数情况下,通常只有一个 AI 概述,但您的代码应准备处理多个条目。
在下面按不同搜索查询分类,探索 AI 概述结果示例: 项目, 食谱, 说明.
项目
在以下示例中,使用了查询 “Emporio Armani EA3192”。
...
"ai_overviews": [
{
"answer_text": [
{
"text": [
"Emporio Armani 是一个以其永恒设计和对意大利工艺承诺而闻名的奢侈品牌。",
"Emporio Armani EA3192 是一款为男士设计的验光眼镜。",
"它们有一个矩形镜框,由低过敏性、轻质塑料制成。",
"镜片具有防紫外线和防反光功能。",
"以下是来自评论的一些见解:"
],
"pos": 1
}
],
"bullet_list": [
{
"list_title": "优点",
"points": [
"舒适",
"品牌标识简约"
],
"pos": 1
}
],
"products": {
"items": [
{
"product_name": "Emporio Armani Men Eyeglasses Shiny Black Size: 53",
"price": "$163.00",
"previous_price": null,
"seller": "Lenscrafters",
"shipping": "免运费",
"url": "https://www.lenscrafters.com/lc-us/emporio-armani/8056597975810?srsltid=AfmBOoqWO55KIJevhQp_c5OAp0JOM_8Uza3_gCvn9S4x4Vz342AUSQewzJI",
"pos": 1
}
]
},
"source_panel": {
"items": [
{
"url": "https://www.italist.com/magazine/what-is-emporio-armani/#:~:text=Emporio%20Armani%20is%20a%20luxury,reinforce%20the%20perception%20of%20luxury.",
"source": "italist.com",
"date": "2023 年 5 月 5 日",
"title": "什么是 Emporio Armani,Emporio Armani 是奢侈品牌吗?",
"pos": 1
},
...
]
},
"additional_questions": {
"items": [
{
"question": "Emporio Armani 与 Giorgio Armani 是同一个品牌吗?",
"pos": 1
}
]
},
"pos_overall": 1
}
],
...答案文本
text
对 Google 搜索查询的简短回答。
array
pos
表示给定项目在所有 AI 概述答案结果中的位置。
integer
项目符号列表
list_title
项目符号列表的标题。
string
points
在项目符号列表中呈现的项目。所有项目以逗号分隔。
array
pos
表示给定项目在所有 AI 概述项目符号列表结果中的位置。
integer
产品
items
包含各自详细信息的产品列表。
array
items.product_name
产品名称。
string
items.price
产品的当前价格。
string
items.previous_price
产品的初始价格(如适用)。
string
items.seller
产品的卖家。
string
items.shipping
产品可用的运输类型。
string
items.url
产品的 URL。
string
items.pos
表示给定项目在所有 AI 概述产品结果中的位置。
integer
来源面板
items
用于生成 Google SERP 中 AI 概述结果的来源列表。
object
items.url
网站的 URL。
string
items.source
网站的名称。
string
items.date
文章的发布日期。
string
items.title
文章的标题。
string
items.pos
表示给定项目在所有 AI 概述来源面板结果中的位置。
integer
补充问题
items.question
与原始搜索查询相关的逗号分隔补充问题列表。
array
items.pos
表示给定项目在所有 AI 概述补充问题结果中的位置。
integer
食谱
在以下示例中,使用了查询 “recipe for an apple pie”。

...
"ai_overviews": [
{
"recipes": {
"items": [
{
"description": "这个简单的食谱以自制馅饼皮、格兰尼史密斯苹果和温暖香料为特色。",
"image": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/...",
"source": "Allrecipes",
"rating": "4.8",
"rating_count": "13K",
"duration": "90 min",
"url": "https://www.allrecipes.com/recipe/12682/apple-pie-by-grandma-ople/",
"title": "Grandma Ople 的苹果馅饼"
},
...
]
}
}
],
...食谱
items
包含各自详细信息的食谱列表。
array
items.description
食谱的简短描述。
string
items.image
食谱的 base64 编码缩略图。
string
items.source
发表该食谱的网站名称。
string
items.rating
食谱的评分。
string
items.rating_count
评分数量。
string
items.duration
准备该菜所需的时间。
string
items.url
完整食谱的 URL。
string
items.title
食谱的标题。
string
在以下示例中,使用了查询 “recipe of a juicy succulent steak”。

信息列表
list_title
列表的标题。
string
list_items
包含具有各自详细信息的项目列表。
array
list_items.title
列表中该部分的标题。
string
list_items.content
该部分的简短描述。
array
list_item.pos
表示某个项目在所有 AI Overviews Info 列表结果中的位置的指标。
integer
说明
在以下示例中,使用了查询 “docker exec commands explained”。

...
"ai_overviews": [
{
"answer_text": [
{
"text": [
“The docker execExecIn computing, exec is a functionality of an operating system that runs an executable file in the context of an already existing process, replacing the previous executable...”,
“It is a powerful tool that can be used for a variety of tasks, such as troubleshooting a container, running a script, or installing software.”
],
"pos": 1
},
{
"text": [
“The syntax for the docker exec command is as follows:”
],
“command": [
“docker exec [OPTIONS] CONTAINER COMMAND [ARG...]”
],
“pos": 2
},
...
}
]
}
],
...回答文本命令
command
给计算机或软件下达以执行特定任务的指令。
string
最后更新于
这有帮助吗?

