CrawlForge MCP
基础工具1 credit

extract_links

发现并提取网页中的所有链接。非常适合站点地图生成、链接分析和爬取工作流。

使用场景

生成站点地图

通过提取所有内部链接构建全面的站点地图

为爬取发现链接

在网页爬取工作流中找出所有要访问的 URL

内部链接分析

分析内部链接结构以进行 SEO 优化

失效链接检测

查找并校验页面上的所有链接

Endpoint

POST/api/v1/tools/extract_links
Auth Required
Free 计划 1 req/s
1 credit

Parameters

NameTypeRequiredDefaultDescription
url
stringOptional-
要抓取并从中提取链接的页面。`url` 与 `html` 二者必填其一。
Example: https://example.com
html
stringOptional-
直接解析的原始 HTML,替代抓取。请配合 `base_url` 使用,以便相对 href 能够解析。
Example: <a href='/about'>About</a>
base_url
stringOptional-
解析相对链接所用的基地址。抓取时默认为 `url`;传入 `html` 时请一并提供。
Example: https://example.com
include_internal
booleanOptionaltrue
包含指向同一主机的链接。
Example: true
include_external
booleanOptionaltrue
包含指向其他主机的链接。设为 false 可只保留内部链接。
Example: true
filter_domains
arrayOptional-
仅保留主机与这些域名之一匹配的链接。
Example: ["docs.example.com"]
include_anchors
booleanOptionalfalse
包含形如 `#section` 的纯片段链接。
Example: false
deduplicate
booleanOptionaltrue
将重复的 URL 合并为一条。
Example: true
include_metadata
booleanOptionaltrue
在 URL 之外一并返回每个链接的锚文本与属性。
Example: true
respect_robots
booleanOptionaltrue
遵守目标站点的 robots.txt。保持 `true` 时,robots.txt 对 `CrawlForge` 禁止的路径会在抓取之前以 403 拒绝,且不扣除 credits。仅在你与目标站点另有约定时才设为 `false`——此时响应会带上一条 `warnings`,并且该覆盖会记录到你的 API key 上。
Example: true

请求示例

cURL - 提取所有链接

terminalBash
curl -X POST https://crawlforge.dev/api/v1/tools/extract_links \
  -H "X-API-Key: cf_test_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com",
    "include_internal": true,
    "include_external": false,
    "deduplicate": true
  }'

TypeScript - 仅内部链接

extractLinks.tsTypescript
const response = await fetch('https://crawlforge.dev/api/v1/tools/extract_links', {
  method: 'POST',
  headers: {
    'X-API-Key': process.env.CRAWLFORGE_API_KEY!,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    url: 'https://example.com',
    // Internal-only: keep include_internal, switch include_external off.
    include_internal: true,
    include_external: false,
    deduplicate: true,
  }),
});

const payload = await response.json();
if (!response.ok) {
  throw new Error(payload.error.code + ': ' + payload.error.message);
}

const result = payload.data;
console.log('Base URL:', result.base_url);
console.log('Extracted from:', result.extracted_from);

for (const link of result.links) console.log(link);

// Narrow to specific hosts instead of a blanket internal/external split.
const docsOnly = await fetch('https://crawlforge.dev/api/v1/tools/extract_links', {
  method: 'POST',
  headers: {
    'X-API-Key': process.env.CRAWLFORGE_API_KEY!,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    url: 'https://example.com',
    filter_domains: ['docs.example.com'],
  }),
});

响应示例

200 OK210ms
{
"success": true,
"data": {
"url": "https://example.com",
"links": [
{
"text": "Home",
"url": "https://example.com/",
"internal": true
},
{
"text": "About",
"url": "https://example.com/about",
"internal": true
},
{
"text": "Products",
"url": "https://example.com/products",
"internal": true
},
{
"text": "External Resource",
"url": "https://other-site.com",
"internal": false
}
],
"total_links": 4,
"internal_links": 3,
"external_links": 1
},
"credits_used": 1,
"credits_remaining": 999,
"processing_time": 210
}
Field Descriptions
data.links所有已发现链接的数组,包含文本和 URL
data.total_links找到的链接总数
data.internal_links指向同域名的链接数量
data.external_links指向外部域名的链接数量

错误处理

被 robots.txt 拦截(403 Forbidden)

目标站点的 robots.txt 对 CrawlForge 禁止了该路径。若你与目标站点另有约定,可设置 respect_robots: false 予以覆盖——该覆盖会记录到你的 API key 上。该覆盖不适用于列入 CrawlForge 永久排除名单的主机——无论 respect_robots 取何值,这类主机一律被拒绝。

相关工具

fetch_url
在提取链接前抓取页面(1 credit)
smart_crawl
带链接发现的智能爬取(8 credits)
准备好提取链接了吗?免费注册,获取 1,000 credits。

页脚

CrawlForge MCP

面向 AI Agent 的企业级网页抓取。29 个专业 MCP 工具,专为构建智能系统的现代开发者而设计。

产品

  • 功能
  • Playground
  • 价格
  • 应用场景
  • 集成
  • 替代方案
  • 更新日志

资源

  • 快速上手
  • API 参考
  • 模板
  • 指南
  • 博客
  • 术语表
  • 常见问题
  • 网站地图

开发者

  • MCP 协议
  • Claude Desktop
  • Cursor IDE
  • LangChain
  • LlamaIndex

公司

  • 关于我们
  • 联系我们
  • 隐私政策
  • 服务条款
  • 可接受使用政策
  • Cookie

保持更新

获取新工具和新功能的最新动态。

基于 Next.js 和 MCP 协议构建

© 2025-2026 CrawlForge。保留所有权利。