Documentation has been updated: see help center and changelog in one place.

Perplexity

了解如何抓取 Perplexity 的响应并使用 Web Scraper API 获取结构化数据。查找全面的代码示例和输出样本。

perplexity source 允许你将提示发送到 Perplexity 并直接捕获完整响应。它以结构化格式返回生成的文本和相关元数据,以及结果的 Markdown 版本。

请求示例

下面的代码示例演示如何向 Perplexity 发送提示并检索已解析的响应。

curl 'https://realtime.oxylabs.io/v1/queries' \
--user 'USERNAME:PASSWORD' \
-H 'Content-Type: application/json' \
-d '{
        "source": "perplexity",
        "prompt": "top 3 smartphones in 2025, compare pricing across US marketplaces",
        "geo_location": "美国",
        "parse": true
    }'

默认情况下,所有对 Perplexity 的请求都使用 JavaScript 渲染。使用 Realtime 集成方法时,请确保设置足够的超时(例如 180s)。

我们的示例使用 Realtime (同步)集成方法。要使用 Proxy EndpointPush-Pull (异步),请参阅 集成方法 页面。

请求参数值

通用

抓取 Perplexity 响应的基本设置和配置参数。

参数
说明
默认值

source

设置要使用的爬虫。

perplexity

prompt

要提交给 Perplexity 的提示或问题。

-

parse

设置为时返回解析数据 true.

false

geo_location

指定要从哪个国家/地区发送提示。 更多信息.

-

callback_url

您的回调端点的 URL。 更多信息.

-

- 强制参数

结构化数据

Web Scraper API 返回 Perplexity 输出的 HTML 文档或 JSON 对象,其中包含来自结果页面的结构化数据。

perplexity 结构化输出

输出数据字典

HTML 示例

JSON 结构

结构化的 perplexity 输出包含的字段例如 url, model, answer_results,以及更多。下表说明了我们解析的页面元素,及其描述、数据类型和相关元数据。

特定结果类型的项目数和字段可能会根据提交的提示而变化。

字段
说明
类型

url

Perplexity 会话的 URL。

字符串

page

页码。

整数

内容

包含已解析 Perplexity 页面数据的对象。

对象

model

用于生成答案的 Perplexity 模型。

字符串

prompt_query

提交给 Perplexity 的原始提示。

字符串

displayed_tabs

Perplexity 界面中显示的选项卡(例如,shopping、images)。

列表

answer_results

包含文本或嵌套内容的完整 Perplexity 响应。

list or string

answer_results_md

以 Markdown 格式渲染的完整答案。

字符串

related_queries

与主提示相关的查询列表。

列表

top_images

包含标题和 URL 的顶级图片列表。

数组

top_sources

包含标题、来源和 URL 的主要引用来源列表。

数组

inline_products

包含标题、价格、链接及其他元数据的内嵌产品列表。

数组

additional_results.hotels_results

包含标题、URL、地址及其他酒店详情的酒店列表。

数组

additional_results.places_results

包含标题、URL、坐标,及其他元数据的地点列表。

数组

additional_results.videos_results

包含缩略图、标题、URL 和来源的视频列表。

数组

additional_results.shopping_results

包含标题、价格、URL 及其他产品元数据的购物条目列表。

数组

additional_results.sources_results

包含标题和 URL 的引用来源列表。

数组

additional_results.images_results

包含标题、图片 URL 和源页面 URL 的相关图片列表。

数组

parse_status_code

解析操作的状态码。

整数

created_at

抓取作业创建的时间戳。

timestamp

updated_at

抓取作业完成的时间戳。

timestamp

job_id

与抓取作业关联的作业 ID。

字符串

geo_location

提交提示时使用的代理位置。

字符串

status_code

抓取作业的状态码。您可以在此处查看爬虫状态码说明 此处.

整数

parser_type

用于解析 HTML 内容的解析器类型。

字符串

附加结果和内嵌产品

除了主要的 AI 响应外,我们在 additional_results下返回额外数据,诸如

  • images_results

  • sources_results

  • shopping_results

  • videos_results

  • places_results

  • hotels_results

这些数组从原始结果页面的选项卡中提取,仅在相关内容可用时包含:

此外, inline_products 数组包含直接嵌入响应中的产品:

最后更新于

这有帮助吗?