网页抓取
通过 /v1/tools/fetch 接口抓取指定 URL 的网页内容,返回页面标题与 Markdown 格式正文。
POST
/
v1
/
tools
/
fetch
网页抓取
curl --request POST \
--url https://api.moonshot.cn/v1/tools/fetch \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"url": "<string>"
}
'import requests
url = "https://api.moonshot.cn/v1/tools/fetch"
payload = { "url": "<string>" }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({url: '<string>'})
};
fetch('https://api.moonshot.cn/v1/tools/fetch', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.moonshot.cn/v1/tools/fetch",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'url' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.moonshot.cn/v1/tools/fetch"
payload := strings.NewReader("{\n \"url\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.moonshot.cn/v1/tools/fetch")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"url\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.moonshot.cn/v1/tools/fetch")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"url\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"url": "<string>",
"markdown": "<string>",
"title": "<string>"
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}抓取指定 URL 的网页内容,返回页面标题与 Markdown 格式正文,适用于网页阅读、资料整理等内容提取场景。
响应示例markdown 内容形态示例通用响应头
以上两个响应头在所有响应(包括错误响应)中均会携带。
仅支持
http 和 https 协议的 URL。触发安全风控的 URL 会返回 403 security_risk 错误;页面无可提取正文时返回 404 markdown_not_found 错误。调用示例
调用示例
import os
import requests
api_key = os.environ.get("MOONSHOT_API_KEY")
url = "https://api.moonshot.cn/v1/tools/fetch"
response = requests.post(
url,
headers={"Authorization": f"Bearer {api_key}"},
json={"url": "https://platform.kimi.com/docs/api/overview"},
)
print(response.json())
curl https://api.moonshot.cn/v1/tools/fetch \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $MOONSHOT_API_KEY" \
-d '{"url": "https://platform.kimi.com/docs/api/overview"}'
const apiKey = process.env.MOONSHOT_API_KEY;
async function main() {
const response = await fetch("https://api.moonshot.cn/v1/tools/fetch", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${apiKey}`,
},
body: JSON.stringify({
url: "https://platform.kimi.com/docs/api/overview",
}),
});
const data = await response.json();
console.log(data);
}
main();
响应字段说明
响应字段说明
| 字段 | 类型 | 说明 |
|---|---|---|
url | string | 抓取 URL |
markdown | string | 抓取结果的 Markdown 内容;文本与图片按在页面中出现的顺序拼接,图片以占位符形式嵌入(格式见下方示例),各段之间以空行分隔 |
title | string | 页面标题 |
{
"url": "https://platform.kimi.com/docs/api/overview",
"markdown": "# API 概述\n\nKimi API 开放平台文档入口。",
"title": "API 概述 - Kimi API 开放平台"
}
# API 概述
Kimi API 开放平台文档入口。

更多正文内容……
| 响应头 | 说明 |
|---|---|
X-Msh-Track-Id | 请求 ID;请求携带同名头时沿用,否则由服务端生成。排查问题时请提供该 ID |
X-Msh-Chat-Id | 会话 ID,固定为 toolgw-{X-Msh-Track-Id};排查问题时请一并提供 |
错误码说明
错误码说明
| HTTP 状态码 | error.type | 典型 message | 说明 |
|---|---|---|---|
| 400 | invalid_request | invalid request body | 请求体不是合法 JSON |
| 400 | invalid_url | The provided URL is invalid: only http and https are supported | URL 为空或协议非 http/https |
| 400 | invalid_url | The provided URL is invalid: missing host | URL 缺少主机名 |
| 401 | - | 无错误响应体 | API Key 缺失或无效 |
| 403 | - | 无错误响应体 | 账号未激活或已停用 |
| 403 | security_risk | We consider the current URL poses a security risk and are unable to provide fetch service at this time. | URL 触发安全风控,请更换 URL |
| 404 | markdown_not_found | No text/markdown content found for the current URL. | 页面无可提取的正文内容 |
| 408 | client_canceled | client canceled the request | 客户端在服务端返回前断开连接 |
| 429 | rate_limited | project concurrency limit exceeded | 触发频率或并发限制;响应头携带 X-RateLimit-Limit、X-RateLimit-Remaining,触发每秒请求数限制时还携带 X-RateLimit-Reset |
| 429 | rate_limit_unavailable | rate limit store unavailable | 限速服务暂时不可用,请稍后重试 |
| 500 | internal_error | 内部错误原文 | 服务内部错误,请稍后重试;若持续出现,请携带 X-Msh-Track-Id 联系支持团队 |
| 502 | upstream_failed | upstream service failed | 服务暂时不可用,请稍后重试 |
| 504 | timeout | request timeout | 抓取超时,请稍后重试 |
计费说明:请求成功(HTTP 200)且返回的
markdown 非空白时,计费一次;请求失败或页面无正文内容时不计费。具体价格详见联网搜索定价。授权
请求体
application/json
要抓取的网页 URL,仅支持 http 和 https 协议。
此页面对您有帮助吗?
⌘I
网页抓取
curl --request POST \
--url https://api.moonshot.cn/v1/tools/fetch \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"url": "<string>"
}
'import requests
url = "https://api.moonshot.cn/v1/tools/fetch"
payload = { "url": "<string>" }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({url: '<string>'})
};
fetch('https://api.moonshot.cn/v1/tools/fetch', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.moonshot.cn/v1/tools/fetch",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'url' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.moonshot.cn/v1/tools/fetch"
payload := strings.NewReader("{\n \"url\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.moonshot.cn/v1/tools/fetch")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"url\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.moonshot.cn/v1/tools/fetch")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"url\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"url": "<string>",
"markdown": "<string>",
"title": "<string>"
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "<string>"
}
}