我构建了一个 Screenshot & Metadata API,可从任何 URL 提取 50 多个字段
发布: (2026年3月13日 GMT+8 20:41)
4 分钟阅读
原文: Dev.to
Source: Dev.to
(请提供需要翻译的正文内容,我将为您翻译成简体中文,并保留原始的格式、Markdown 语法以及技术术语。)
功能说明
- URL to Screenshot – 将任意网页捕获为 PNG、JPEG 或 WebP
- URL to PDF – 生成具有自定义格式、边距和方向的 PDF
- Metadata Extraction – 从任意 URL 提取 50 多个字段(见下文)
- HTML to Image – 将自定义 HTML/CSS 渲染为 PNG/JPEG/WebP
元数据端点
单个 GET 请求提取:
基础 SEO
- title、description、keywords、author、language、charset、viewport、robots、canonical URL、generator
Open Graph
- og:title、og:description、og:image(+ 尺寸)、og:url、og:type、og:site_name、og:locale
Twitter Card
图标与主题
- favicon、apple-touch-icon、manifest、theme-color、color-scheme
内容分析
- 第一个 h1 文本、h2 数量、内部链接数量、外部链接数量、图片数量、无 alt 文本的图片、表单数量、脚本数量、样式表数量、字数
结构化数据
- 解析并返回的 JSON‑LD(Schema.org)
Feed
- 自动检测的 RSS/Atom Feed
原始转储
- 所有 meta 标签的键‑值对
快速入门 (Python)
import requests
headers = {
"X-RapidAPI-Key": "YOUR_KEY",
"X-RapidAPI-Host": "screenshot-pdf-api.p.rapidapi.com"
}
# 截图网站
response = requests.get(
"https://screenshot-pdf-api.p.rapidapi.com/v1/screenshot",
headers=headers,
params={"url": "https://github.com", "width": 1280, "format": "png"}
)
with open("screenshot.png", "wb") as f:
f.write(response.content)
print(f"Saved {len(response.content)} bytes")快速开始 (JavaScript)
// Screenshot
const response = await fetch(
"https://screenshot-pdf-api.p.rapidapi.com/v1/screenshot?url=https://github.com&format=png",
{
headers: {
"X-RapidAPI-Key": "YOUR_KEY",
"X-RapidAPI-Host": "screenshot-pdf-api.p.rapidapi.com"
}
}
);
const blob = await response.blob();
// Metadata
const meta = await fetch(
"https://screenshot-pdf-api.p.rapidapi.com/v1/metadata?url=https://github.com",
{
headers: {
"X-RapidAPI-Key": "YOUR_KEY",
"X-RapidAPI-Host": "screenshot-pdf-api.p.rapidapi.com"
}
}
);
const data = await meta.json();
console.log(data.data.title); // "GitHub · Build and ship software..."
console.log(data.data.og_image); // "https://..."
console.log(data.data.word_count); // 834cURL
# 截图
curl -o screenshot.png \
-H "X-RapidAPI-Key: YOUR_KEY" \
-H "X-RapidAPI-Host: screenshot-pdf-api.p.rapidapi.com" \
"https://screenshot-pdf-api.p.rapidapi.com/v1/screenshot?url=https://github.com"
# 完整页面捕获
curl -o fullpage.png \
-H "X-RapidAPI-Key: YOUR_KEY" \
-H "X-RapidAPI-Host: screenshot-pdf-api.p.rapidapi.com" \
"https://screenshot-pdf-api.p.rapidapi.com/v1/screenshot?url=https://en.wikipedia.org&full_page=true"端点
| 端点 | 描述 | 等级 |
|---|---|---|
GET /v1/screenshot | 将截图 URL 转换为 PNG/JPEG/WebP | Free |
GET /v1/health | API 状态和队列深度 | Free |
GET /v1/pdf | 从 URL 生成 PDF | Basic |
GET /v1/metadata | 提取 50 多个元数据字段 | Basic |
POST /v1/screenshot/html | 将 HTML/CSS 渲染为图像 | Pro |
Screenshot Parameters
| 参数 | 默认值 | 描述 |
|---|---|---|
url | required | 要捕获的 URL |
width | 1280 | 视口宽度 |
height | 800 | 视口高度 |
format | png | png, jpeg, webp |
quality | 85 | JPEG/WebP 质量(1‑100) |
full_page | false | 捕获整个可滚动页面 |
delay | 0 | 捕获前等待 N 秒(0‑5) |
selector | null | 用于捕获特定元素的 CSS 选择器 |
用例
- 社交媒体预览 – 生成 Open Graph 图片
- PDF 报告 – 将仪表板和页面转换为 PDF
- 网络爬取 – 一次调用获取截图和元数据
- 缩略图 – 大规模生成网站缩略图
- SEO 审计 – 检查 OG 标签、缺失的 alt 文本、结构化数据
- 链接预览 – 构建丰富的预览卡片
- 可视化回归测试 – 为 QA 自动化截图
定价与竞争对手比较
| 功能 | 此 API | ScreenshotOne | URLBox |
|---|---|---|---|
| 免费层 | 20/天 | 一次性 100 | 无 |
| 基础套餐 | $9/月 | $17/月 | $19/月 |
| 元数据提取 | 50+ 字段 | 否 | 否 |
| JSON‑LD 解析 | 是 | 否 | 否 |
| 内容分析 | 是 | 否 | 否 |
试用
使用 FastAPI + Playwright(无头 Chromium)构建。托管在 Hetzner VPS 上。