Skip to content

OnPage Lighthouse 支持的版本

GET /v3/on_page/lighthouse/versions

本接口用于查询 OnPage Lighthouse API 当前支持的 Lighthouse 版本列表。请求方式与路径为:

http
GET https://api.seermartech.cn/v3/on_page/lighthouse/versions

OnPage Lighthouse API 基于开源 Lighthouse 项目,可用于获取网页质量数据。调用 OnPage Lighthouse 任务接口时,可在 POST 请求中指定 Lighthouse 版本;未指定时,系统将使用标记为默认版本的版本。

当前查询支持版本接口不收取费用。扣费以响应头 X-SeerMarTech-Charge-CNY 为准。

请求参数

该 GET 接口无需请求参数,也无需请求体。

响应字段

顶层响应字段

字段类型说明
versionstring当前 API 版本
status_codeinteger通用状态码,成功时通常为 20000。完整状态码请参考错误码文档
status_messagestring通用状态说明
timestring接口执行耗时,单位为秒
costfloat平台原始 USD 成本兼容字段;人民币实扣以 X-SeerMarTech-Charge-CNY 为准。
tasks_countintegertasks 数组中的任务数量
tasks_errorintegertasks 数组中返回错误的任务数量
tasksarray任务结果数组

tasks 数组字段

字段类型说明
idstring任务唯一标识,采用 UUID 格式
status_codeinteger任务状态码,通常位于 1000060000 范围
status_messagestring任务状态说明
timestring任务执行耗时,单位为秒
costfloat平台原始 USD 成本兼容字段;人民币实扣以 X-SeerMarTech-Charge-CNY 为准。
result_countintegerresult 数组中的数量
patharray请求 URL 路径
dataobject请求任务时提交的参数。对于本接口,通常 API 和功能名称
resultarray任务结果数组

result 数组字段

字段类型说明
available_versionsarray当前支持的 Lighthouse 版本列表
available_versions[].versionstringLighthouse 版本号
available_versions[].defaultboolean是否为默认版本。为 false 时,如需使用该版本,应在对应的 OnPage Lighthouse POST 请求中明确指定

available_versions 数组中的每个都版本号,以及表示该版本是否为默认版本的布尔值。

请求示例

cURL

bash
curl --location --request GET \
  "https://api.seermartech.cn/v3/on_page/lighthouse/versions" \
  --header "Authorization: Bearer smt_live_YOUR_KEY" \
  --header "Content-Type: application/json"

TypeScript

typescript
import axios from "axios";

axios({
  method: "get",
  url: "https://api.seermartech.cn/v3/on_page/lighthouse/versions",
  headers: {
    Authorization: "Bearer smt_live_YOUR_KEY",
    "Content-Type": "application/json",
  },
})
  .then((response) => {
    // 处理响应数据
    console.log(response.data);
  })
  .catch((error) => {
    console.error("请求失败:", error.response?.data || error.message);
  });

Python

python
import requests

url = "https://api.seermartech.cn/v3/on_page/lighthouse/versions"

headers = {
    "Authorization": "Bearer smt_live_YOUR_KEY",
    "Content-Type": "application/json",
}

response = requests.get(url, headers=headers)

if response.ok:
    result = response.json()
    if result.get("status_code") == 20000:
        print(result)
    else:
        print(
            "接口返回错误:{} {}".format(
                result.get("status_code"),
                result.get("status_message"),
            )
        )
else:
    print("HTTP 请求失败:", response.status_code, response.text)

PHP

php
<?php

$ch = curl_init('https://api.seermartech.cn/v3/on_page/lighthouse/versions');

curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer smt_live_YOUR_KEY',
        'Content-Type: application/json',
    ],
]);

$response = curl_exec($ch);

if ($response === false) {
    echo '请求失败:' . curl_error($ch);
    curl_close($ch);
    exit;
}

curl_close($ch);

$result = json_decode($response, true);

if (($result['status_code'] ?? null) === 20000) {
    print_r($result);
} else {
    echo '接口返回错误:'
        . ($result['status_code'] ?? '未知')
        . ' '
        . ($result['status_message'] ?? '未知错误');
}

C#

csharp
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;

public class LighthouseVersionsDemo
{
    public static async Task Main()
    {
        using var httpClient = new HttpClient();

        httpClient.DefaultRequestHeaders.Authorization =
            new AuthenticationHeaderValue("Bearer", "smt_live_YOUR_KEY");

        var response = await httpClient.GetAsync(
            "https://api.seermartech.cn/v3/on_page/lighthouse/versions"
        );

        var responseText = await response.Content.ReadAsStringAsync();

        if (response.IsSuccessStatusCode)
        {
            Console.WriteLine(responseText);
        }
        else
        {
            Console.WriteLine(
                $"HTTP 请求失败:{(int)response.StatusCode} {responseText}"
            );
        }
    }
}

响应示例

以下示例表示接口成功返回支持的 Lighthouse 版本列表:

json
{
  "version": "0.1.20210917",
  "status_code": 20000,
  "status_message": "Ok.",
  "time": "0.2232 sec.",
  "cost": 0,
  "tasks_count": 1,
  "tasks_error": 0,
  "tasks": [
    {
      "id": "00000000-0000-0000-0000-000000000000",
      "status_code": 20000,
      "status_message": "Ok.",
      "time": "0.1000 sec.",
      "cost": 0,
      "result_count": 1,
      "path": [
        "v3",
        "on_page",
        "lighthouse",
        "versions"
      ],
      "data": {
        "api": "on_page",
        "function": "lighthouse"
      },
      "result": [
        {
          "available_versions": [
            {
              "version": "10.4.0",
              "default": true
            },
            {
              "version": "9.6.8",
              "default": false
            }
          ]
        }
      ]
    }
  ]
}

状态码与异常处理

请在业务系统中根据顶层及任务级别的 status_codestatus_message 处理异常:

  • 顶层 status_code 用于表示本次接口请求的整体状态。
  • tasks[].status_code 用于表示任务的处理状态。
  • tasks_error 大于 0 时,表示至少有一个任务返回错误。
  • 成功响应通常使用状态码 20000
  • 建议对网络时、HTTP 错误、非成功状态码及响应字段缺失等进行统一处理。

实用场景

  • 查询可用 Lighthouse 版本:在创建网页质量检测任务前获取平台当前支持的版本,提交不容的版本号。
  • 固定检测版本:根据返回结果选择指定 Lighthouse 版本,确保不同时间或不同项目之间的检测口径一致。
  • 识别默认版本:读取 default 字段,在不指定版本时自动采用平台推荐版本,降低任务复杂度。
  • 管理 SEO 检测:将支持版本列表同步到 SEO 平台或中心,便于运营人员选择检测版本。
  • 监控版本变更:定期对比接口返回的版本列表,及时发现新增、下线或默认版本变化,并评估对历史数据的影响。

统一入口:官网 · LLM API · 控制台