HTML 解析(HTML 转 Markdown)API 接口
由万码云开发平台提供的 HTML 解析(HTML 转 Markdown)API 接口,支持解析 HTML 中的文本、图片、链接、表格等多种元素,提供灵活的参数配置以适应不同场景需求。接口设计简单明了,易于集成和调用,适用于内容提取、数据分析以及 RAG(Retrieval-Augmented Generation)等多个应用场景,帮助开发者高效实现 HTML 解析相关功能,为智能问答和知识管理等应用提供可靠支持。
接口地址(免费版,文件大小不超过 2 MB)
POST https://wcode.net/api/parse/v3/html/free
注:免费版接口限制并发为 12 QPM(Query Per Minute,每分钟处理请求数)
接口地址(付费版,文件大小不超过 32 MB)
POST https://wcode.net/api/parse/v3/html
付费版价格:0.01 元 / 500 字符(即解析 50000 字符的费用为 1 元),费用充值:https://wcode.net/apikey-recharge,费用发票:https://wcode.net/get-fapiao
字符数的计算:包含单字节字符、多字节字符、标点符号等,具体以下方接口响应示例为准。
字符数的计费:总字符数如果不足 500 字符,以 500 字符计费(即 0.01 元)。
请求方法
POST
快速开始(请求示例)
(注:以下请求示例中的 API_KEY
需要替换后再发起请求。 获取 API_KEY
入口:https://wcode.net/get-apikey)
curl --request POST 'https://wcode.net/api/parse/v3/html' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer API_KEY' \
--data '{
"file_url": "https://www.example.com"
}'
请求头(Request Headers)
Header | 值 | 备注 | 示例 | 相关链接 |
---|---|---|---|---|
Authorization | Bearer API_KEY |
格式:Bearer + 空格 + API_KEY | Bearer sk-..... |
获取 API_KEY 入口:https://wcode.net/get-apikey |
Content-Type | application/json |
固定为 application/json |
请求参数
参数 | 必填 | 参数类型 | 默认值 | 说明 |
---|---|---|---|---|
file_url |
是 | string | - | 要解析的 HTML 文件 URL,支持网页 URL |
注意事项:
file_url
需支持公网访问;- 调用 API 时,接口服务端会向
file_url
发起请求,请求的User-agent
为:
Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko); compatible; WCodeNET/2.1; +https://wcode.net/parse-html-api
请确保此User-agent
可正常访问file_url
; file_url
对应文件的大小不能超过 32 MB,且不能小于 1 KB;- 服务端下载
file_url
超时时间为20
秒,超时将会返回失败,请确保file_url
网络通畅;
返回参数
返回参数 | 数据类型 | 说明 |
---|---|---|
status | string | 请求成功返回success ,失败返回failed |
error_message | string | 接口返回的错误消息。当status 为success 时,error_message 为空字符串 |
error_code | int 或 null | 接口返回的错误码。当status 为success 时,error_code 为 null |
data | object 或 null | 接口返回的数据。当status 为failed 时,data 为 null |
data.markdown | string | Markdown 格式的解析结果 |
data.html | string | HTML 格式的解析结果 |
data.usage | object | 本次解析的统计与费用信息 |
data.usage.total_characters | int | 本次解析的字符数统计 |
data.usage.total_cost | float | 本次解析产生的费用 |
data.api_version | string | 当前所使用的 API 的版本,免费版为free ,付费版为paid |
data.api_docs | string | 当前所使用的 API 的文档链接 |
响应头(Response Headers)
Header | 说明 | 示例 | 相关链接 |
---|---|---|---|
X-Account-Balance | API_KEY 余额(元) | 123.0165 |
API_KEY 费用充值入口:https://wcode.net/apikey-recharge |
请求示例
curl --request POST 'https://wcode.net/api/parse/v3/html' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer API_KEY' \
--data '{
"file_url": "https://www.example.com"
}'
响应示例
{
"status": "success",
"error_message": "",
"error_code": null,
"data": {
"markdown": "\n# Example Domain\n\nThis domain is for use in illustrative examples in documents. You may use this\ndomain in literature without prior coordination or asking for permission.\n\n[More information...](https://www.iana.org/domains/example)\n\n\n",
"html": "<h1>Example Domain</h1>\n<p>This domain is for use in illustrative examples in documents. You may use this\ndomain in literature without prior coordination or asking for permission.</p>\n<p><a href=\"https://www.iana.org/domains/example\">More information...</a></p>\n",
"usage": {
"total_characters": 201,
"total_cost": 0.01,
"total_cost_currency": "CNY",
"total_cost_currency_symbol": "¥"
},
"api_version": "paid",
"api_docs": "https://wcode.net/parse-html-api"
}
}
Python 代码示例(Requests)
import requests
import json
url = "https://wcode.net/api/parse/v3/html"
payload = json.dumps({
"file_url": "https://www.example.com"
})
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer API_KEY' # TODO: 这里的 API_KEY 需要替换,获取 API_KEY 入口:https://wcode.net/get-apikey
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
Java 代码示例(OkHttp)
OkHttpClient client = new OkHttpClient().newBuilder().build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\"file_url\": \"https://www.example.com\"}");
Request request = new Request.Builder()
.url("https://wcode.net/api/parse/v3/html")
.method("POST", body)
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "Bearer API_KEY") // TODO: 这里的 API_KEY 需要替换,获取 API_KEY 入口:https://wcode.net/get-apikey
.build();
Response response = client.newCall(request).execute();
PHP 代码示例(Guzzle)
<?php
$client = new Client();
$headers = [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer API_KEY' // TODO: 这里的 API_KEY 需要替换,获取 API_KEY 入口:https://wcode.net/get-apikey
];
$body = '{
"file_url": "https://www.example.com"
}';
$request = new Request('POST', 'https://wcode.net/api/parse/v3/html', $headers, $body);
$res = $client->sendAsync($request)->wait();
echo $res->getBody();
...其他编程语言可参考 curl http 请求示例进行调用
异常响应示例
{
"status": "failed",
"error_message": "The file format (...) is not supported, please check the file url (https://...) to ensure that the file type matches the required format and try again",
"error_code": 415,
"data": null
}