API文档
在线截图工具的API接口说明,帮助开发者快速集成截图功能
API概览
我们提供简单易用的截图API接口,支持各种截图需求,包括常规截图、定时截图、元素截图等功能。
快速开始
基本请求示例
curl -X POST https://api.example.com/screenshot \
-H "Content-Type: application/json" \
-d '{"url": "https://www.example.com", "width": 1920, "height": 1080}'
API接口
常规截图
接口地址:POST /screenshot
功能说明:对指定URL进行截图
请求参数
| 参数名 | 类型 | 必填 | 描述 |
|---|---|---|---|
| url | string | 是 | 要截图的网页地址 |
| width | number | 否 | 截图宽度,默认1920 |
| height | number | 否 | 截图高度,默认1080 |
| device | string | 否 | 设备类型:desktop/tablet/mobile |
| fullpage | boolean | 否 | 是否全屏截图,默认false |
响应示例
{
"code": 200,
"message": "success",
"data": {
"url": "https://api.example.com/screenshots/123456.png",
"width": 1920,
"height": 1080,
"size": 1024000
}
}
定时截图
接口地址:POST /screenshot/schedule
功能说明:设置定时截图任务
请求参数
| 参数名 | 类型 | 必填 | 描述 |
|---|---|---|---|
| url | string | 是 | 要截图的网页地址 |
| schedule | string | 是 | 定时表达式,如:0 0 * * * (每天凌晨) |
| width | number | 否 | 截图宽度,默认1920 |
| height | number | 否 | 截图高度,默认1080 |
| string | 否 | 截图完成后通知邮箱 |
响应示例
{
"code": 200,
"message": "success",
"data": {
"task_id": "schedule_123456",
"next_run": "2023-01-01T00:00:00Z",
"schedule": "0 0 * * *"
}
}
元素截图
接口地址:POST /screenshot/element
功能说明:截取网页中指定元素的部分
请求参数
| 参数名 | 类型 | 必填 | 描述 |
|---|---|---|---|
| url | string | 是 | 要截图的网页地址 |
| selector | string | 是 | CSS选择器,用于定位要截图的元素 |
| wait_time | number | 否 | 页面加载完成后等待时间(毫秒),默认0 |
响应示例
{
"code": 200,
"message": "success",
"data": {
"url": "https://api.example.com/screenshots/element_123456.png",
"element": ".main-content",
"size": 512000
}
}
批量截图
接口地址:POST /screenshot/batch
功能说明:对多个URL进行批量截图
请求参数
| 参数名 | 类型 | 必填 | 描述 |
|---|---|---|---|
| urls | array | 是 | 要截图的网页地址数组 |
| width | number | 否 | 截图宽度,默认1920 |
| height | number | 否 | 截图高度,默认1080 |
| device | string | 否 | 设备类型:desktop/tablet/mobile |
响应示例
{
"code": 200,
"message": "success",
"data": {
"batch_id": "batch_123456",
"total": 3,
"results": [
{
"url": "https://www.example.com/page1",
"screenshot_url": "https://api.example.com/screenshots/batch_123456_1.png"
},
{
"url": "https://www.example.com/page2",
"screenshot_url": "https://api.example.com/screenshots/batch_123456_2.png"
},
{
"url": "https://www.example.com/page3",
"screenshot_url": "https://api.example.com/screenshots/batch_123456_3.png"
}
]
}
}
登录截图
接口地址:POST /screenshot/login
功能说明:登录指定网站后进行截图
请求参数
| 参数名 | 类型 | 必填 | 描述 |
|---|---|---|---|
| login_url | string | 是 | 登录页面地址 |
| target_url | string | 是 | 登录后要截图的页面地址 |
| username_selector | string | 是 | 用户名输入框的CSS选择器 |
| username | string | 是 | 登录用户名 |
| password_selector | string | 是 | 密码输入框的CSS选择器 |
| password | string | 是 | 登录密码 |
| submit_selector | string | 是 | 登录按钮的CSS选择器 |
| width | number | 否 | 截图宽度,默认1920 |
| height | number | 否 | 截图高度,默认1080 |
响应示例
{
"code": 200,
"message": "success",
"data": {
"url": "https://api.example.com/screenshots/login_123456.png",
"login_status": "success",
"size": 1536000
}
}
错误码说明
| 错误码 | 描述 |
|---|---|
| 400 | 参数错误 |
| 401 | 未授权访问 |
| 403 | 权限不足 |
| 404 | 页面不存在 |
| 500 | 服务器错误 |
API密钥
使用API需要先注册获取API密钥,每个API请求需要在请求头中携带API密钥:
Authorization: Bearer YOUR_API_KEY