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": "United States",
        "parse": true
    }'

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

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

请求参数值

通用

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

参数
描述
默认值

source

设置要使用的爬取器。

perplexity

prompt

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

-

parse

设置为 true.

false

geo_location

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

-

callback_url

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

-

- 必需参数

结构化数据

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

perplexity 结构化输出

输出数据字典

HTML 示例

JSON 结构

结构化 perplexity 输出包括诸如以下字段 url, model, answer_results,等。下表列出了我们解析的页面元素,包含描述、数据类型和相关元数据。

特定结果类型的项目和字段数量可能因提交的提示而异。

字段
描述
类型

url

Perplexity 会话的 URL。

string

page

页码。

integer

content

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

object

model

用于生成答案的 Perplexity 模型。

string

prompt_query

提交给 Perplexity 的原始提示。

string

displayed_tabs

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

list

answer_results

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

list or string

answer_results_md

以 Markdown 格式呈现的完整答案。

string

related_queries

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

list

top_images

包含标题和 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

解析操作的状态码。

integer

created_at

创建爬取任务的时间戳。

timestamp

updated_at

爬取任务完成的时间戳。

timestamp

job_id

与爬取任务关联的作业 ID。

string

geo_location

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

string

status_code

爬取任务的状态码。你可以在此处查看爬虫状态码的说明 here.

integer

parser_type

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

string

附加结果和内联产品

除了主要的 AI 回应外,我们还在下列字段返回额外数据: additional_results,例如

  • images_results

  • sources_results

  • shopping_results

  • videos_results

  • places_results

  • hotels_results

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

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

最后更新于

这有帮助吗?