主题
获取 OnPage Lighthouse 已完成任务
GET /v3/on_page/lighthouse/tasks_ready
本接口使用 GET 方法,路径为:
/v3/on_page/lighthouse/tasks_ready
接口说明
本接口用于获取尚未领取的 OnPage Lighthouse 已完成任务列表。
如果使用标准任务提交方式,且未设置 postback_url,可以通过本接口获取已完成任务的 id,再调用任务结果接口获取结果。
每个任务在被成功领取前都会保留在列表中。任务完成后 3 天仍未领取的任务,将从列表中移除。
请求地址
http
GET https://api.seermartech.cn/v3/on_page/lighthouse/tasks_ready计费与限制
- 获取任务列表本身不产生费用。
- 每分钟最多调用 20 次。
- 每次调用最多返回过去 3 天完成的 1000 个任务。
- 已经领取的任务不会再次出现在列表中。
- 如果提交任务时设置了
postback_url,任务通常不会出现在本接口的结果中。 - 只有在向回调地址推送失败,且服务端返回的 HTTP 状态码小于
200或大于300时,任务才可能重新出现在已完成任务列表中。 - 实扣费以响应头
X-SeerMarTech-Charge-CNY为准。
接口返回 JSON 数据 tasks 数组。
请求头
http
Authorization: Bearer smt_live_YOUR_KEY
Content-Type: application/json响应字段
顶层字段
| 字段 | 类型 | 说明 |
|---|---|---|
version | string | 当前 API 版本 |
status_code | integer | 接口级状态码。完整状态码列表请参考 /v3/appendix/errors |
status_message | string | 接口级提示信息 |
time | string | 接口执行耗时,单位为秒 |
cost | float | 平台原始 USD 成本兼容字段;人民币实扣以 X-SeerMarTech-Charge-CNY 为准。 |
tasks_count | integer | tasks 数组中的任务数量 |
tasks_error | integer | tasks 数组中返回错误的任务数量 |
tasks | array | 已完成任务列表 |
tasks 数组字段
| 字段 | 类型 | 说明 |
|---|---|---|
id | string | 任务唯一标识,UUID 格式 |
status_code | integer | 任务状态码,取值范围通常为 10000-60000。完整状态码列表请参考 /v3/appendix/errors |
status_message | string | 任务状态说明 |
time | string | 任务处理耗时,单位为秒 |
cost | float | 平台原始 USD 成本兼容字段;人民币实扣以 X-SeerMarTech-Charge-CNY 为准。 |
result_count | integer | result 数组中的数量 |
path | array | 请求路径信息 |
data | object | 创建任务时传的请求参数 |
result | array | 已完成任务结果信息 |
tasks[].result 数组字段
| 字段 | 类型 | 说明 |
|---|---|---|
id | string | 已完成任务的唯一标识,UUID 格式 |
tag | string | 用户自定义任务标识 |
endpoint_json | string | 获取 OnPage Lighthouse JSON 结果的接口地址 |
请求示例
cURL
bash
curl --location --request GET \
"https://api.seermartech.cn/v3/on_page/lighthouse/tasks_ready" \
--header "Authorization: Bearer smt_live_YOUR_KEY" \
--header "Content-Type: application/json"Python
python
import requests
url = "https://api.seermartech.cn/v3/on_page/lighthouse/tasks_ready"
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 请求失败:{} {}".format(response.status_code, response.text))TypeScript
typescript
import axios from "axios";
async function getReadyTasks(): Promise<void> {
try {
const response = await axios.get(
"https://api.seermartech.cn/v3/on_page/lighthouse/tasks_ready",
{
headers: {
Authorization: "Bearer smt_live_YOUR_KEY",
"Content-Type": "application/json",
},
}
);
const result = response.data;
if (result.status_code === 20000) {
console.log(result);
// 在这里处理已完成任务列表
} else {
console.error(
`接口错误,状态码:${result.status_code},信息:${result.status_message}`
);
}
} catch (error) {
console.error("请求失败:", error);
}
}
getReadyTasks();PHP
php
<?php
$url = 'https://api.seermartech.cn/v3/on_page/lighthouse/tasks_ready';
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer smt_live_YOUR_KEY',
'Content-Type: application/json',
],
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($response === false) {
echo '请求失败:' . curl_error($ch);
} else {
$result = json_decode($response, true);
if (($result['status_code'] ?? null) === 20000) {
print_r($result);
// 在这里处理已完成任务列表
} else {
echo '接口错误,状态码:' .
($result['status_code'] ?? $httpCode) .
',信息:' .
($result['status_message'] ?? '未知错误');
}
}
curl_close($ch);C#
csharp
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
public class LighthouseTasksReadyDemo
{
public static async Task Main()
{
using var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", "smt_live_YOUR_KEY");
httpClient.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json")
);
var response = await httpClient.GetAsync(
"https://api.seermartech.cn/v3/on_page/lighthouse/tasks_ready"
);
var content = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
Console.WriteLine(content);
// 在这里解析并处理已完成任务列表
}
else
{
Console.WriteLine(
$"HTTP 请求失败:{(int)response.StatusCode} {response.ReasonPhrase}"
);
}
}
}响应示例
json
{
"version": "0.1.20210713",
"status_code": 20000,
"status_message": "Ok.",
"time": "0.2064 sec.",
"cost": 0,
"tasks_count": 1,
"tasks_error": 0,
"tasks": [
{
"id": "01234567-89ab-cdef-0123-456789abcdef",
"status_code": 20000,
"status_message": "Ok.",
"time": "0.1800 sec.",
"cost": 0,
"result_count": 1,
"path": [
"v3",
"on_page",
"lighthouse",
"task_get",
"01234567-89ab-cdef-0123-456789abcdef"
],
"data": {
"api": "on_page",
"function": "lighthouse"
},
"result": [
{
"id": "01234567-89ab-cdef-0123-456789abcdef",
"tag": "example-task",
"endpoint_json": "/v3/on_page/lighthouse/task_get/01234567-89ab-cdef-0123-456789abcdef"
}
]
}
]
}响应状态码
20000:请求成功。- 状态码:请求或任务处理异常。建议根据
status_code和status_message实现异常处理机制。
完整错误码请参考:
/v3/appendix/errors
后续获取任务结果
获取到任务 id 或 endpoint_json 后,可继续调用对应的任务结果接口,获取 OnPage Lighthouse 的详细分析结果。任务结果接口应以响应中的 endpoint_json 为准。
实用场景
- 轮询已完成任务:定期获取尚未领取的 Lighthouse 任务,遗漏异步 SEO 审计结果。
- 构建任务消费队列:将返回的任务
id加队列,再由工作进程批量获取结果,提高大规模站点检测的处理效率。 - 监控异步任务积压:根据
tasks_count统计领取任务数量,及时发现结果处理服务延迟或异常。 - 补偿回调失败任务:在回调服务不可用时,通过任务列表发现未成功推送的结果,降低 Lighthouse 数据丢失风险。
- 汇总站点性能数据:批量领取已完成任务并获取详细结果,为 SEO 技术审计、Core Web Vitals 监控和页面性能报表提供数据。