主题
获取 WordPress V2 搜索结果 HTML
GET /v3/serp/wp/v2/task_get/html/$id
通过任务 ID 获取已完成的 WordPress V2 SERP 任务的原始 HTML 页面。本接口可查询已提交任务的结果;任务结果自创建起保留 7 天,在保留期可重复获取。
任务费用在提交任务时收取,查询本接口不会重复计费。扣费以响应头 X-SeerMarTech-Charge-CNY 为准。
请求参数
路径参数
| 参数 | 类型 | 填 | 说明 |
|---|---|---|---|
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]
# 任务状态码大于等于 40000 时表示任务处理失败
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
import axios from "axios";
const taskId = "02261816-2027-0066-0000-c27d02864073";
async function getTaskHtml() {
const response = await axios.get(
`https://api.seermartech.cn/v3/serp/wp/v2/task_get/html/${taskId}`,
{
headers: {
Authorization: "Bearer smt_live_YOUR_KEY",
"Content-Type": "application/json",
},
},
);
const result = response.data;
//局请求成功不代表单个任务一定成功
if (result.status_code !== 20000) {
throw new Error(`请求失败:${result.status_code} - ${result.status_message}`);
}
const task = result.tasks[0];
if (task.status_code >= 40000 || !task.result) {
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 表示请求成功。错误码说明请参考错误码文档。 |
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 范围;状态码大于等于 40000 时应按失败处理。 |
status_message | string | 任务状态说明。 |
time | string | 当前任务处理耗时,单位为秒。 |
cost | float | 平台原始 USD 成本兼容字段;人民币实扣以 X-SeerMarTech-Charge-CNY 为准。 |
result_count | integer | result 数组中的结果对象数量。 |
path | array | 用于获取当前结果的接口路径。 |
data | object | 创建任务时提交的原始参数。 |
result | array | 搜索结果数组。 |
data 对象字段
data 会返回创建任务时指定的参数,常见字段如下:
| 字段 | 类型 | 说明 |
|---|---|---|
api | string | API 类别,通常为 serp。 |
function | string | 功能名称,通常为 task_get。 |
se | string | 搜索引擎标识,本接口为 wp。 |
se_type | string | 搜索类型,本接口为 v2。 |
keyword | string | 请求时提交的。经过 URL 编码的字符会被解码;加号(+)会转换为空格。 |
location_code | integer | 地区代码。 |
language_name | string | 语言名称。 |
language_code | string | 语言代码。 |
tag | string | 创建任务时传的自定义标签。 |
device | string | 设备类型,例如 desktop。 |
os | string | 操作系统,例如 windows。 |
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 | 返回的搜索结果页面数据。 |
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.2104 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",
"language_name": "English",
"location_code": 2840,
"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": 2840,
"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;即使顶层请求成功,单个任务仍可能因任务不存在、任务未完成或已过期而失败。 - 当任务状态码大于等于
40000时,应记录status_message并执行重试、告警或人工排查。 - 任务结果保留 7 天。建议在任务完成后及时拉取并持化
html,结果过期无法再次获取。
实用场景
- 归档搜索结果快:获取并保存指定的原始 SERP HTML,为后续排名波动追溯和页面证据留存提供依据。
- 解析自然搜索版位:从返回的 HTML 中提取标题、链接、摘要及页面模块,评估目标的竞争格局。
- 监测结果页结构变化:定期对比同一的 HTML 快,识别搜索页面布局、富结果或广告区域的变化。
- 验证本地化搜索展示:结合任务中的地区和语言参数检查 HTML,确认不同市场下的搜索结果差异。
- 构建自定义 SERP 解析器:将原始 HTML解析规则或机器学习流程,提取符合自身业务定义的搜索结果字段。