extract_content
抓取页面,去掉外壳,返回页面上真正的内容。导航、页眉、页脚、侧边栏、script、style 和广告容器都会被移除,然后定位正文并以纯文本或 HTML 返回,同时给出页面声明的标题、署名和发布日期。
使用场景
RAG 数据摄取
在切块和向量化之前把文章转成干净文本,避免导航菜单污染每一个片段。
阅读视图
渲染无干扰版本的页面,把 clean_html 设为 false 即可保留 HTML 结构。
署名提取
从页面自身的 meta 标签中获取作者与发布日期,用于署名或时效性检查。
图片采集
把文章内的每张图片都作为绝对 URL 返回,且已相对页面自身地址解析完成。
引用关系图
启用 include_links 可抓取正文内部的外链——而不是站点导航中的链接。
内容迁移
把旧站点的文章 HTML 提取出来,迁移到别处,同时不带走旧模板。
Endpoint
/api/v1/tools/extract_contentParameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
url | string | Required | - | 要提取内容的页面。必须是有效的绝对 http 或 https URL。 Example: https://example.com/blog/crawl-budgets |
include_images | boolean | Optional | true | 把提取区域内的每个 `<img>` 作为绝对 URL 返回,并附 `image_count`。无法相对页面 URL 解析的源会被跳过。设为 false 时这两个键都不会出现。 Example: true |
include_links | boolean | Optional | false | 把提取区域内的每个 `<a href>` 作为带绝对 href 的 `{ href, text }` 返回,并附 `link_count`。默认关闭——开启后这两个键才会出现。 Example: true |
clean_html | boolean | Optional | true | true 返回压缩空白后的纯文本,并把 `content_type` 设为 `text`。false 返回该区域的内部 HTML,并把 `content_type` 设为 `html`——同样已移除模板元素。 Example: true |
extract_main_content | boolean | Optional | true | 收窄到正文区域,依次尝试 `<article>`、`<main>`、`.content`、`#content`,都不匹配时回退到 `<body>`。设为 false 则保留整个 body。 Example: true |
timeout | number | Optional | 10000 | 抓取超时(毫秒),取值 1000 到 30000。 Example: 10000 |
respect_robots | boolean | Optional | true | 遵守目标站点的 robots.txt。保持 `true` 时,robots.txt 对 `CrawlForge` 禁止的路径会在抓取之前以 403 拒绝,且不扣除 credits。仅在你与目标站点另有约定时才设为 `false`——此时响应会带上一条 `warnings`,并且该覆盖会记录到你的 API key 上。 Example: true |
请求示例
curl -X POST https://crawlforge.dev/api/v1/tools/extract_content \
-H "X-API-Key: cf_test_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com/blog/crawl-budgets",
"include_links": true
}'响应示例
{ "success": true, "data": { "url": "https://example.com/blog/crawl-budgets", "content": "Why crawl budgets matter Search engines allocate a finite number of requests to each site. See the sitemap guide for the mechanics.", "content_length": 131, "content_type": "text", "title": "Why crawl budgets matter — Acme Blog", "author": "Dana Reyes", "publish_date": "2026-08-14T09:30:00Z", "images": [ "https://example.com/img/crawl-budget.png" ], "image_count": 1, "links": [ { "href": "https://example.com/docs/sitemaps", "text": "sitemap guide" } ], "link_count": 1 }, "credits_used": 2, "credits_remaining": 998, "processing_time": 680}data.content提取出的区域。压缩连续空白后的纯文本;`clean_html` 为 false 时则是内部 HTMLdata.content_length`content` 的字符数——数值很小通常意味着该页面是客户端渲染的data.content_type`text` 或 `html`,与 `clean_html` 对应data.title整个页面的 `<title>` 元素,而不是文章内部的标题data.author取自页面的 `meta[name=author]` 标签。页面未声明时为 `null`data.publish_date取自 `meta[property=article:published_time]`,原样返回。不存在时为 `null`data.images相对页面地址解析后的绝对 URL。`include_images` 为 true 时出现data.links仅限提取区域内部的链接。`include_links` 为 true 时出现credits_used每页固定 2 credits错误处理
URL 无效(400 Bad Request)
VALIDATION_ERROR。url 为必填且必须能解析为绝对 URL。timeout 超出 1000-30000 也返回同一状态码。
页面过大(413 Payload Too Large)
RESPONSE_TOO_LARGE。页面超过 25MB 读取上限,被直接拒绝而不是缓冲到内存。
目标站点超时(504 Gateway Timeout)
FETCH_TIMEOUT。页面在发送响应体的过程中停止响应。可以调高 timeout,最大 30000 毫秒。
抓取失败(502 Bad Gateway)
FETCH_FAILED。无法读取响应体——连接被重置,或响应体不是可解码的文本。
提取失败(500 Internal Server Error)
TOOL_ERROR。失败的调用不计费;只有提取成功后才会扣除 credits。
被 robots.txt 拦截(403 Forbidden)
目标站点的 robots.txt 对 CrawlForge 禁止了该路径。若你与目标站点另有约定,可设置 respect_robots: false 予以覆盖——该覆盖会记录到你的 API key 上。该覆盖不适用于列入 CrawlForge 永久排除名单的主机——无论 respect_robots 取何值,这类主机一律被拒绝。
content,而不是报错。如果某个在浏览器里看得到的页面返回的 content_length 接近于零,请改用 scrape_with_actions。credits 费用
包含内容:
移除模板元素(nav、header、footer、aside、广告、script、style)
正文区域检测,并以 <body> 作为回退
干净文本或文章 HTML
来自页面 meta 的标题、作者与发布日期
文章内部图片与链接的绝对 URL
计划推荐:
Free 计划: 1,000 个一次性试用 credits = 500 页
Hobby 计划: 5,000 credits = 2,500 页($19/mo)
Professional 计划: 50,000 credits = 25,000 页($99/mo)