使用场景
SEO 分析
分析页面标题、描述和关键词以进行优化
社交媒体预览数据
获取 OpenGraph 和 Twitter Card 数据,用于丰富的社交预览
内容分类
使用元数据对网页内容进行分类和整理
生成链接预览
用标题、图片和描述构建丰富的链接预览
Endpoint
POST
/api/v1/tools/extract_metadataAuth Required
Free 计划 1 req/s
1 credit
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
url | string | Optional | - | 要从中提取元数据的页面。`url` 与 `html` 二者必填其一。 Example: https://example.com/article |
html | string | Optional | - | 直接解析的原始 HTML,替代抓取。 Example: <html>...</html> |
include_social | boolean | Optional | true | 包含 Open Graph、Twitter 卡片、Facebook app id 与站点验证标签。 Example: true |
include_seo | boolean | Optional | true | 包含 description、keywords、author、robots、canonical、标题层级与 viewport。 Example: true |
include_technical | boolean | Optional | true | 包含 generator、favicon、样式表与脚本。 Example: true |
include_structured_data | boolean | Optional | true | 包含页面上找到的 JSON-LD 结构化数据块。 Example: true |
respect_robots | boolean | Optional | true | 遵守目标站点的 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_metadata \
-H "X-API-Key: cf_test_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com/article"}'TypeScript
extractMetadata.tsTypescript
const response = await fetch('https://crawlforge.dev/api/v1/tools/extract_metadata', {
method: 'POST',
headers: {
'X-API-Key': process.env.CRAWLFORGE_API_KEY!,
'Content-Type': 'application/json',
},
body: JSON.stringify({
url: 'https://example.com/article'
}),
});
const data = await response.json();
if (data.success) {
const { title, description, og, twitter } = data.data;
console.log('Title:', title);
console.log('Description:', description);
console.log('OG Image:', og.image);
console.log('Twitter Card:', twitter.card);
}响应示例
200 OK195ms
{ "success": true, "data": { "metadata": { "basic": { "title": "Example Article - Best Practices Guide", "url": "https://example.com/article", "lang": "en", "charset": "utf-8" }, "seo": { "description": "Learn the best practices for web development", "keywords": "web development, best practices, tutorial", "author": "Jane Doe", "robots": "index, follow", "canonical": "https://example.com/article", "headings": { "h1": [ "Best Practices Guide" ], "h2": [ "Getting Started", "Common Pitfalls" ], "h3": [] }, "meta_refresh": null, "viewport": "width=device-width, initial-scale=1" }, "social": { "open_graph": { "title": "Example Article - Best Practices Guide", "image": "https://example.com/og-image.jpg", "type": "article", "site_name": "Example Site" }, "twitter": { "card": "summary_large_image", "site": "@examplesite" }, "facebook_app_id": null, "google_site_verification": null }, "technical": { "generator": "Next.js", "favicons": [ { "rel": "icon", "href": "/favicon.ico", "type": "image/x-icon" } ] }, "structured_data": [] }, "summary": { "has_title": true, "has_description": true, "has_open_graph": true, "has_twitter_cards": true, "has_structured_data": false, "total_headings": 3 }, "extracted_from": "https://example.com/article", "extraction_time": "2026-08-26T14:30:00.000Z" }, "credits_used": 1, "credits_remaining": 999, "processing_time": 195}Field Descriptions
data.metadata.basic始终存在:标题、解析后的 url、html 的 lang 与字符集。data.metadata.seo当 `include_seo` 为 true 时出现。包含完整的 h1/h2/h3 标题层级结构。data.metadata.social.open_graph页面声明的全部 `og:` 属性,原样返回。页面没有声明时为 null。data.metadata.social.twitter页面声明的全部 `twitter:` 属性。没有时为 null。data.metadata.technical当 `include_technical` 为 true 时出现:generator、favicon、样式表与脚本。data.metadata.structured_data页面上找到的 JSON-LD 块。没有时为空数组。data.summary一组布尔值,便于快速检查完整性,无需遍历整个 metadata 对象。data.extracted_from来源 URL;若您传入的是 `html`,则为字面量字符串 'provided HTML'。data.extraction_time本次提取的 ISO 8601 时间戳。错误处理
被 robots.txt 拦截(403 Forbidden)
目标站点的 robots.txt 对 CrawlForge 禁止了该路径。若你与目标站点另有约定,可设置 respect_robots: false 予以覆盖——该覆盖会记录到你的 API key 上。该覆盖不适用于列入 CrawlForge 永久排除名单的主机——无论 respect_robots 取何值,这类主机一律被拒绝。
相关工具
准备好提取元数据了吗?免费注册,获取 1,000 credits。