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

Realtime

Oxylabs 的 Web Scraper API 的 Realtime 集成。保持 HTTPS 连接从任务提交直到返回结果或错误,使用 JSON 格式的负载。

Realtime 是一种同步集成方法。它 需要保持连接打开 直到任务成功完成或返回错误为止。

任务提交

端点

用于任务提交的 Realtime API 端点为:

POST https://realtime.oxylabs.io/v1/queries

输入

以 JSON 有效负载的形式提供任务参数,如下面的示例所示。Python 和 PHP 示例包含注释以便说明。

curl --user "USERNAME:PASSWORD" \
'https://realtime.oxylabs.io/v1/queries' \
-H "Content-Type: application/json" \
-d '{"source": "universal", "url": "https://example.com", "geo_location": "United States"}'

输出

Realtime API 在输出中支持以下结果类型:

  • HTML: 从目标网页抓取的原始 HTML 内容;

  • JSON: 从 HTML 内容解析出的结构化数据,以 JSON 格式呈现;

  • PNG: 以 PNG 格式渲染页面的 Base64 编码截图。

  • Markdown: Markdown 网页的。

你也可以在单个 API 响应中检索 多种结果类型

下表说明了基于 API 请求负载中包含的参数,默认和其他可用的结果类型。

渲染参数
解析参数
默认输出
可用输出

x

x

html

html

html

x

html

html

png

x

png

html, png

x

true

json

html, json

html

true

json

html, json

png

true

png

html, json, png

Realtime API 始终返回默认输出。要从同一 realtime 任务获取其他可用输出,请使用 Push-Pull 端点 并使用该任务 ID。请注意,任务 ID 可在每个 realtime 响应的头部以及响应体中找到。

输出示例:

{
  "results": [
    {
      "content": "<html>
      内容
      </html>",
      "created_at": "2024-06-26 13:13:06",
      "updated_at": "2024-06-26 13:13:07",
      "id": null,
      "page": 1,
      "url": "https://www.example.com/",
      "job_id": "12345678900987654321",
      "status_code": 200
    }
  ]
}

最后更新于

这有帮助吗?