获取解析结果接口
更新时间:2026-09-16
面向企业办公与知识库场景的结构化文档解析服务:支持 PDF、Word、Excel、图片等 18 种主流格式,自动完成版面分析、表格还原、标题层级与阅读顺序识别,并可输出 Markdown 等结构化结果,识别准确率可达 90% 以上;同时具备角度矫正、水印擦除等工程能力,支持 20 余种语种。
POST
https://aip.baidubce.com/rest/2.0/brain/online/v2/parser/task/query
权限说明
调用本文API,需使用API Key鉴权方式。使用API Key鉴权调用API流程,具体调用流程,请查看认证鉴权
请求参数
Headers 参数
除公共头域外,还包含以下特殊头域
Authorization
string
API Key 鉴权,示例值:Bearer {API-Key}
必选
Content-Type
string
application/x-www-form-urlencoded
必选
Body 参数
task_id
string
发送提交请求时返回的task_id
必选
请求结构
POST /rest/2.0/brain/online/v2/parser/task/query HTTP/1.1
Host: aip.baidubce.com
Authorization: Bearer YOUR_API_KEY
Content-Type: application/x-www-form-urlencoded
task_id=your_task_id
示例代码
请求示例
import requests
API_KEY = "bce-v3/ALTAK-xxxxxxxx/xxxxxxxxxxxxxxxx"
QUERY_URL = "https://aip.baidubce.com/rest/2.0/brain/online/v2/parser/task/query"
def query_task(task_id):
"""
Args:
task_id: string, 任务id
Returns: 响应
"""
headers = {
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": f"Bearer {API_KEY}",
}
data = {
"task_id": task_id,
}
response = requests.post(QUERY_URL, headers=headers, data=data, timeout=120)
return response
if __name__ == '__main__':
# 需要替换为实际的任务id
task_id = "your_task_id"
print(query_task(task_id).json())
返回响应
Headers 参数
除公共头域外,无其它特殊头域
返回参数
log_id
integer
唯一的log id,用于问题定位
可选
error_code
integer
错误码
可选
error_msg
string
错误描述信息
可选
result
object {7}
返回的结果
可选
显示子属性
隐藏子属性
task_id
string
任务ID
可选
status
string
任务状态:pending(排队中)、running(运行中)、success(成功)、failed(失败)
可选
task_error
string
解析报错信息,包含任务失败、额度不够
可选
markdown_url
string
文档解析结果的markdown格式链接,链接有效期30天
可选
parse_result_url
string
文档解析结果的Json链接,有效期30天。可通过parse_result_url下载解析结果的JSON文件,返回参数如下:
- file_name (string):文档名称
- file_id (string):文档ID
- pages (array):文件单页解析内容列表,每页包含:
- page_id (string):页码ID
- page_num (int):页码数,从0开始
- text (string):当前页的所有纯文字内容,含表格Markdown
- layouts (array):页面内容版式分析的结果,每项包含:
- layout_id (string):layout元素唯一标志,以xxxxx-layout-{global_layout_index}形式,global_layout_index为layout元素整个文档的全局索引
- text (string):layout对应的文本内容,type为table或image时该字段为空,需到tables或images字段查找
- position (array):layout元素在页面中的位置[x, y, w, h],左上角坐标和宽高
- type (string):layout元素类型,可取值:text(段落)、table(表格)、head_tail(页面顶部)、image(插图)、contents(目录)、seal(印章)、title(标题)、formula(公式)、hand_sign(手写签名)
- sub_type (string):layout元素子类型。title类:title_{n}(n级标题)、image_title(图标题)、table_title(表标题);image类:chart(统计图表)、figure(普通插图)、QR_code(二维码)、Bar_code(条形码)
- parent (string):标题层级树中父节点的layout_id,一级标题的parent为root
- children (array):标题层级树中子节点的layout_id列表,每项为string
- tables (array):页面表格解析结果,每项包含:
- layout_id (string):layout ID,与layouts中type为table的元素对应
- markdown (string):表格内容的markdown形式
- html (string):表格HTML,html_table_format=true(默认)时有值
- table_title_id (array):表格标题对应的layout_id,默认为null,每项为string
- position (array):边框数据[x, y, w, h],(x,y)为坐标点,w为box宽度,h为box高度,版式格式时有效
- cells (array):单元格的内嵌版面信息,layout类型为表格时有值
- matrix (array):二维数组,表示表格内布局位置信息,每个元素对应cells列表中元素的索引
- merge_table (string):跨页表格标记:begin(开始)、inner(中间)、end(结束);非跨页表格为空
- images (array):页面中图片解析结果,每项包含:
- layout_id (string):layout ID,与layouts中type为image的元素对应
- image_title_id (array):图片标题对应的layout_id,默认为null,每项为string
- position (array):边框数据[x, y, w, h],(x,y)为坐标点,w为box宽度,h为box高度,版式格式时有效
- content_layouts (array):图片的内嵌版面信息
- data_url (string):图片存储链接,有效期30天
- image_description (string):对统计图表进行内容解析和描述,输出结果为json字符串,可通过json.loads结构化
- meta (object):页面元信息,包含:
- page_width (int):页面宽度
- page_height (int):页面高度
- is_scan (bool):是否扫描件
- page_angle (int):页面倾斜角度
- page_type (string):页面属性,包括:text(正文)、contents(目录)、appendix(附录)、[doc](含有文档插图)、[seal](签章页)、others(其他)
- sheet_name (string):excel的sheet名
- chunks (array):文件内容切分结果,return_doc_chunks中switch为True时有值,每项包含:
- chunk_id (string):切片的ID
- content (string):切片的内容
- type (string):切片类型,为text或table
- meta (object):chunk元信息,包含:
- title (array):chunk所属的多级标题内容,每项为string
- position (array):chunk的位置,根据分块算法有可能chunk跨多个页
- box (array):chunk的位置坐标
- page_num (int):chunk内容所在页数
可选
pdf_file_url
string
整份PDF链接,仅need_pdffile_data=true且status=success时返回,有效期30天
可选
cost_page_num
integer
任务解析页数,即该任务对应的消耗额度
可选
响应示例
# 成功返回示例
{
"log_id": "23596597899286921761579365582373",
"error_code": 0,
"error_msg": "",
"result":
{
"task_id": "task-UnvGsgbYZp9pS3BZRHn11ifzjNvKzTgf",
"status": "success",
"task_error": null,
"duration": 902.0,
"parse_result_url": "https:xxxxxxxxxxxxxxxxxxx"
}
}
# 解析结果示例
{
"file_name": "文档解析样例页.png",
"file_id": "file-u9kVDu6dtwMyNrizbejMlF8A852aJLm2",
"pages": [
{
"page_id": "2aJLm2-page-0",
"page_num": 0,
"text": "智能文档分析 | 解析样例\n2 复杂版面解析说明\n本文用于展示文档解析接口对页眉、标题、段落、公式、表格、插图和页脚的综合识别结果。阅读顺序按人类阅读习惯从左到右、从上到下排列。\n2.1 公式与段落\n版面检测后,对识别置信度做归一化。设原始打分为 x,则映射得分 S 定义为:\nS = 1 / (1 + e^{-x})\n当 x 增大时 S 趋近 1。公式在返回 JSON 中对应 type 为 formula 的版面块。\n2.2 表格识别\n表 1 列出常见版面元素与接口字段的对应关系。\n| 元素 | 返回 type | 说明 |\n| --- | --- | --- |\n| 标题 | title | sub_type 为 title_n |\n| 段落 | text | 正文阅读顺序 |\n| 公式 | formula | 需开启 recognize_formula |\n| 表格 | table | cells 与 matrix 描述单元格 |\n| 插图 | image | 图题为 image_title |\n表 1 版面元素与返回字段\n2.3 插图与图题\n图 1 近三年版面识别准确率(%)\n内部资料 仅供接口文档示例\n第 1 页\n",
"layouts": [
{
"layout_id": "2aJLm2-layout-1",
"text": "智能文档分析 | 解析样例",
"position": [48, 28, 499, 22],
"type": "head_tail",
"sub_type": "",
"parent": "root",
"children": []
},
{
"layout_id": "2aJLm2-layout-2",
"text": "2 复杂版面解析说明",
"position": [48, 62, 220, 24],
"type": "title",
"sub_type": "title_1",
"parent": "root",
"children": ["2aJLm2-layout-3", "2aJLm2-layout-4", "2aJLm2-layout-9", "2aJLm2-layout-13"]
},
{
"layout_id": "2aJLm2-layout-3",
"text": "本文用于展示文档解析接口对页眉、标题、段落、公式、表格、插图和页脚的综合识别结果。阅读顺序按人类阅读习惯从左到右、从上到下排列。",
"position": [48, 92, 499, 40],
"type": "text",
"sub_type": "",
"parent": "2aJLm2-layout-2",
"children": []
},
{
"layout_id": "2aJLm2-layout-4",
"text": "2.1 公式与段落",
"position": [48, 140, 140, 20],
"type": "title",
"sub_type": "title_2",
"parent": "2aJLm2-layout-2",
"children": ["2aJLm2-layout-5", "2aJLm2-layout-6", "2aJLm2-layout-7"]
},
{
"layout_id": "2aJLm2-layout-5",
"text": "版面检测后,对识别置信度做归一化。设原始打分为 x,则映射得分 S 定义为:",
"position": [48, 164, 499, 36],
"type": "text",
"sub_type": "",
"parent": "2aJLm2-layout-4",
"children": []
},
{
"layout_id": "2aJLm2-layout-6",
"text": "S = 1 / (1 + e^{-x})",
"position": [96, 208, 400, 36],
"type": "formula",
"sub_type": "",
"parent": "2aJLm2-layout-4",
"children": []
},
{
"layout_id": "2aJLm2-layout-7",
"text": "当 x 增大时 S 趋近 1。公式在返回 JSON 中对应 type 为 formula 的版面块。",
"position": [48, 252, 499, 20],
"type": "text",
"sub_type": "",
"parent": "2aJLm2-layout-4",
"children": []
},
{
"layout_id": "2aJLm2-layout-9",
"text": "2.2 表格识别",
"position": [48, 284, 140, 20],
"type": "title",
"sub_type": "title_2",
"parent": "2aJLm2-layout-2",
"children": ["2aJLm2-layout-10", "2aJLm2-layout-11", "2aJLm2-layout-12"]
},
{
"layout_id": "2aJLm2-layout-10",
"text": "表 1 列出常见版面元素与接口字段的对应关系。",
"position": [48, 308, 499, 18],
"type": "text",
"sub_type": "",
"parent": "2aJLm2-layout-9",
"children": []
},
{
"layout_id": "2aJLm2-layout-11",
"text": "",
"position": [48, 330, 499, 148],
"type": "table",
"sub_type": "",
"parent": "2aJLm2-layout-9",
"children": []
},
{
"layout_id": "2aJLm2-layout-12",
"text": "表 1 版面元素与返回字段",
"position": [48, 484, 200, 16],
"type": "title",
"sub_type": "table_title",
"parent": "2aJLm2-layout-9",
"children": []
},
{
"layout_id": "2aJLm2-layout-13",
"text": "2.3 插图与图题",
"position": [48, 512, 140, 20],
"type": "title",
"sub_type": "title_2",
"parent": "2aJLm2-layout-2",
"children": ["2aJLm2-layout-14", "2aJLm2-layout-15"]
},
{
"layout_id": "2aJLm2-layout-14",
"text": "",
"position": [48, 536, 499, 140],
"type": "image",
"sub_type": "chart",
"parent": "2aJLm2-layout-13",
"children": []
},
{
"layout_id": "2aJLm2-layout-15",
"text": "图 1 近三年版面识别准确率(%)",
"position": [48, 682, 240, 16],
"type": "title",
"sub_type": "image_title",
"parent": "2aJLm2-layout-13",
"children": []
},
{
"layout_id": "2aJLm2-layout-16",
"text": "内部资料 仅供接口文档示例",
"position": [48, 800, 220, 14],
"type": "head_tail",
"sub_type": "",
"parent": "root",
"children": []
},
{
"layout_id": "2aJLm2-layout-17",
"text": "第 1 页",
"position": [500, 800, 48, 14],
"type": "head_tail",
"sub_type": "",
"parent": "root",
"children": []
}
],
"tables": [
{
"layout_id": "2aJLm2-layout-11",
"markdown": "| 元素 | 返回 type | 说明 |\n| --- | --- | --- |\n| 标题 | title | sub_type 为 title_n |\n| 段落 | text | 正文阅读顺序 |\n| 公式 | formula | 需开启 recognize_formula |\n| 表格 | table | cells 与 matrix 描述单元格 |\n| 插图 | image | 图题为 image_title |\n",
"html": "<table><thead><tr><th>元素</th><th>返回 type</th><th>说明</th></tr></thead><tbody><tr><td>标题</td><td>title</td><td>sub_type 为 title_n</td></tr><tr><td>段落</td><td>text</td><td>正文阅读顺序</td></tr><tr><td>公式</td><td>formula</td><td>需开启 recognize_formula</td></tr><tr><td>表格</td><td>table</td><td>cells 与 matrix 描述单元格</td></tr><tr><td>插图</td><td>image</td><td>图题为 image_title</td></tr></tbody></table>",
"table_title_id": ["2aJLm2-layout-12"],
"position": [48, 330, 499, 148],
"cells": [
{"layout_id": "2aJLm2-layout-11-0", "text": "元素", "position": [48, 330, 80, 24], "type": "text", "sub_type": "", "parent": "", "children": null},
{"layout_id": "2aJLm2-layout-11-1", "text": "返回 type", "position": [128, 330, 120, 24], "type": "text", "sub_type": "", "parent": "", "children": null},
{"layout_id": "2aJLm2-layout-11-2", "text": "说明", "position": [248, 330, 299, 24], "type": "text", "sub_type": "", "parent": "", "children": null},
{"layout_id": "2aJLm2-layout-11-3", "text": "标题", "position": [48, 354, 80, 24], "type": "text", "sub_type": "", "parent": "", "children": null},
{"layout_id": "2aJLm2-layout-11-4", "text": "title", "position": [128, 354, 120, 24], "type": "text", "sub_type": "", "parent": "", "children": null},
{"layout_id": "2aJLm2-layout-11-5", "text": "sub_type 为 title_n", "position": [248, 354, 299, 24], "type": "text", "sub_type": "", "parent": "", "children": null}
],
"matrix": [
[0, 1, 2],
[3, 4, 5],
[6, 7, 8],
[9, 10, 11],
[12, 13, 14],
[15, 16, 17]
],
"merge_table": ""
}
],
"images": [
{
"layout_id": "2aJLm2-layout-14",
"image_title_id": ["2aJLm2-layout-15"],
"position": [48, 536, 499, 140],
"content_layouts": [],
"data_url": "https://bj.bcebos.com/v1/example/2aJLm2-layout-14.png",
"image_description": ""
}
],
"meta": {
"page_width": 595,
"page_height": 842,
"is_scan": false,
"page_angle": 0,
"page_type": "doc",
"sheet_name": ""
}
}
],
"chunks": [
{
"chunk_id": "2aJLm2-chunk-0",
"content": "版面检测后,对识别置信度做归一化。设原始打分为 x,则映射得分 S 定义为:\nS = 1 / (1 + e^{-x})\n当 x 增大时 S 趋近 1。公式在返回 JSON 中对应 type 为 formula 的版面块。",
"type": "text",
"meta": {
"title": ["2 复杂版面解析说明", "2.1 公式与段落"],
"position": [{"box": [48, 164, 499, 108], "page_num": 0}]
}
},
{
"chunk_id": "2aJLm2-chunk-1",
"content": "| 元素 | 返回 type | 说明 |\n| --- | --- | --- |\n| 标题 | title | sub_type 为 title_n |\n| 段落 | text | 正文阅读顺序 |\n| 公式 | formula | 需开启 recognize_formula |\n| 表格 | table | cells 与 matrix 描述单元格 |\n| 插图 | image | 图题为 image_title |\n",
"type": "table",
"meta": {
"title": ["2 复杂版面解析说明", "2.2 表格识别"],
"position": [{"box": [48, 330, 499, 148], "page_num": 0}]
}
}
]
}
错误码
如果调用失败并返回报错信息,请参见以下错误码进行解决: 公共错误码:查看公共错误码 OCR 错误码:查看 OCR 错误码
评价此篇文章
