主题
获取 WordPress V2 SERP 任务的 HTML 结果
GET /v3/appendix/errors
GET /v3/serp/wp/v2/task_get/html/$id
通过任务 ID 获取已完成的 WordPress V2 SERP 任务的原始 HTML 页面。任务结果自创建起保留 7 天,可在有效期重复获取;任务费用在创建任务时扣除。扣费以响应头 X-SeerMarTech-Charge-CNY 为准。
请求地址
text
https://api.seermartech.cn/v3/serp/wp/v2/task_get/html/{id}路径参数
| 参数 | 类型 | 填 | 说明 |
|---|---|---|---|
id | string | 是 | 任务唯一标识符,采用 UUID 格式。任务创建后可在 7 天用于查询结果。 |
请求示例
curl
bash
TASK_ID="02261816-2027-0066-0000-c27d02864073"
curl --location --request GET \
"https://api.seermartech.cn/v3/serp/wp/v2/task_get/html/${TASK_ID}" \
--header "Authorization: Bearer smt_live_YOUR_KEY" \
--header "Content-Type: application/json"Python
python
import requests
task_id = "02261816-2027-0066-0000-c27d02864073"
response = requests.get(
f"https://api.seermartech.cn/v3/serp/wp/v2/task_get/html/{task_id}",
headers={
"Authorization": "Bearer smt_live_YOUR_KEY",
"Content-Type": "application/json",
},
timeout=30,
)
response.raise_for_status()
result = response.json()
# 检查接口和任务状态
if result["status_code"] == 20000:
task = result["tasks"][0]
if task["status_code"] < 40000 and task.get("result"):
html = task["result"][0]["items"][0]["html"]
print(html)
else:
print(f"任务错误:{task['status_code']} - {task['status_message']}")
else:
print(f"请求错误:{result['status_code']} - {result['status_message']}")TypeScript
typescript
const taskId = "02261816-2027-0066-0000-c27d02864073";
async function getTaskHtml() {
const response = await fetch(
`https://api.seermartech.cn/v3/serp/wp/v2/task_get/html/${taskId}`,
{
method: "GET",
headers: {
Authorization: "Bearer smt_live_YOUR_KEY",
"Content-Type": "application/json",
},
},
);
if (!response.ok) {
throw new Error(`HTTP 请求失败:${response.status}`);
}
const result = await response.json();
if (result.status_code !== 20000) {
throw new Error(`接口错误:${result.status_code} - ${result.status_message}`);
}
const task = result.tasks?.[0];
if (!task || task.status_code >= 40000 || !task.result?.length) {
throw new Error(`任务错误:${task?.status_code} - ${task?.status_message}`);
}
const html = task.result[0].items?.[0]?.html;
console.log(html);
}
getTaskHtml().catch(console.error);响应结构
接口返回 JSON 对象,顶层 tasks 数组本次查询对应的任务信息。
顶层字段
| 字段 | 类型 | 说明 |
|---|---|---|
version | string | 当前 API 版本。 |
status_code | integer | 接口整体状态码。20000 表示请求成功。完整状态码说明参考 /v3/appendix/errors。 |
status_message | string | 接口整体状态说明。 |
time | string | 请求处理耗时,单位为秒。 |
cost | float | 平台原始 USD 成本兼容字段;人民币实扣以 X-SeerMarTech-Charge-CNY 为准。 |
tasks_count | integer | tasks 数组中的任务数量。 |
tasks_error | integer | 返回错误的任务数量。 |
tasks | array | 任务结果数组。 |
tasks 数组字段
| 字段 | 类型 | 说明 |
|---|---|---|
id | string | 任务唯一标识符,UUID 格式。 |
status_code | integer | 单个任务的状态码。状态码范围通常为 10000 至 60000。 |
status_message | string | 单个任务的状态说明。 |
time | string | 任务处理耗时,单位为秒。 |
cost | float | 平台原始 USD 成本兼容字段;人民币实扣以 X-SeerMarTech-Charge-CNY 为准。 |
result_count | integer | result 数组中的结果数量。 |
path | array | 当前请求对应的 API 路径信息。 |
data | object | 创建任务时提交的原始参数。 |
result | array | SERP HTML 查询结果数组。 |
tasks[].data 字段
该对象保留创建任务时提交的主要参数,常见字段如下:
| 字段 | 类型 | 说明 |
|---|---|---|
api | string | API 分类,通常为 serp。 |
function | string | 调用功能,通常为 task_get。 |
se | string | 搜索引擎标识,当前为 wp。 |
se_type | string | 搜索类型,当前为 v2。 |
keyword | string | 查询。编码后的 %## 会被解码,+ 会还原为空格。 |
location_code | integer | 地区代码。 |
language_code | string | 语言代码。 |
tag | string | 创建任务时传的自定义标签。 |
device | string | 设备类型,例如 desktop。 |
os | string | 操作系统,例如 windows。 |
tasks[].result 数组字段
| 字段 | 类型 | 说明 |
|---|---|---|
keyword | string | 实查询的。 |
type | string | 创建任务时指定的搜索引擎类型。 |
se_domain | string | 搜索引擎域名。 |
location_code | integer | 创建任务时指定的地区代码。 |
language_code | string | 创建任务时指定的语言代码。 |
datetime | string | 获取结果的时间,UTC 格式:yyyy-mm-dd hh:mm:ss +00:00。 |
items_count | integer | items 数组中的数量。 |
items | array | 返回的 HTML 页面数据。 |
tasks[].result[].items 字段
| 字段 | 类型 | 说明 |
|---|---|---|
page | integer | 返回的 HTML 页码序号。 |
date | string | HTML 页面抓取时间,UTC 格式:yyyy-mm-dd hh:mm:ss +00:00。 |
html | string | 搜索结果页的原始 HTML。 |
响应示例
json
{
"version": "0.1.20200129",
"status_code": 20000,
"status_message": "Ok.",
"time": "0.3212 sec.",
"cost": 0,
"tasks_count": 1,
"tasks_error": 0,
"tasks": [
{
"id": "02261816-2027-0066-0000-c27d02864073",
"status_code": 20000,
"status_message": "Ok.",
"time": "0.2451 sec.",
"cost": 0,
"result_count": 1,
"path": [
"v3",
"serp",
"wp",
"v2",
"task_get",
"html",
"02261816-2027-0066-0000-c27d02864073"
],
"data": {
"api": "serp",
"function": "task_get",
"se": "wp",
"se_type": "v2",
"location_code": 2156,
"keyword": "flight ticket new york san francisco",
"tag": "tag1",
"device": "desktop",
"os": "windows"
},
"result": [
{
"keyword": "flight ticket new york san francisco",
"type": "v2",
"se_domain": "wordpress.com",
"location_code": 2156,
"language_code": "en",
"datetime": "2019-11-15 12:57:46 +00:00",
"items_count": 1,
"items": [
{
"page": 1,
"date": "2019-11-15 12:57:46 +00:00",
"html": "<!doctype html><html>...</html>"
}
]
}
]
}
]
}状态与错误处理
建议同时检查顶层和任务级别的状态码:
- 顶层
status_code = 20000:接口请求已成功处理。 - 任务级别
tasks[].status_code = 20000:目标任务结果可正常读取。 - 任务级别状态码大于或等于
40000:任务执行或查询失败,应根据status_message进行处理。 result_count = 0:任务可能尚未完成、结果不可用,或任务 ID 已 7 天有效期。
完整错误码及说明请参考 /v3/appendix/errors。生产环境应针对网络时、鉴权失败、任务未完成、任务过期和服务端错误设计重试及异常处理机制。
实用场景
- 归档 SERP 原始页面:保存指定和地区对应的 HTML 快,为排名波动复盘、页面取证和历史对比提供原始数据依据。
- 解析自然搜索:从返回 HTML 中提取标题、链接、摘要及页面结构,补标准化 SERP 结果字段未覆盖的信息。
- 监测结果页版式变化:定期对同一的 HTML 进行 DOM 对比,识别广告位、富媒体模块或自然结果布局的变化。
- 验证采集结果:将 HTML 原文与已解析的排名数据交叉核对,排查解析规则失效、遗漏或异常排序问题。
- 构建自定义 SERP 解析器:基于完整 HTML 开发适特定业务字段的解析逻辑,支持品牌露出、竞品页面模块和类型识别。