松智云 网页截图 API Python SDK
Project description
松智云 Python SDK
松智云网页截图 API 的 Python 客户端库。支持 Python 3.8+。
环境要求
- Python 3.8 或更高版本
- 松智云 API Key(免费注册获取)
安装
pip install songzhiyun
快速开始
from songzhiyun import SongzhiClient
client = SongzhiClient("sk-xxx")
result = client.screenshot("https://example.com")
print(result["imageUrl"])
# → /screenshots/d55c14ca.png
完整选项
from songzhiyun import SongzhiClient
client = SongzhiClient("sk-xxx")
result = client.screenshot(
"https://example.com",
width=1920,
height=1080,
full_page=True, # 全页长图
mobile=True, # 移动端模拟
wait_ms=2000, # 页面加载后额外等待
format="png", # png / jpeg / webp / pdf
quality=95, # 图片质量 1-100(jpeg/webp)
ad_block=True, # 广告拦截
watermark={
"text": "机密文档",
"position": "bottom-right", # top-left / top-right / center / bottom-left / bottom-right
"opacity": 50, # 0-100
},
)
print(result["imageUrl"])
Python SDK 自动将 snake_case 参数转换为 API 要求的 camelCase。
参数说明
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
width |
int | 1280 | 视口宽度(像素) |
height |
int | 720 | 视口高度(像素) |
full_page |
bool | False | 全页截图(长图) |
mobile |
bool | False | 移动端 User-Agent + 375 宽视口 |
wait_ms |
int | 0 | 页面加载后额外等待(毫秒) |
format |
str | "png" | 输出格式:png / jpeg / webp / pdf |
quality |
int | 90 | 图片质量 1-100(jpeg/webp) |
ad_block |
bool | True | 广告拦截 |
watermark |
dict | None | 水印配置 {"text":"...", "position":"...", "opacity":50} |
异步模式
# 提交任务(立即返回 taskId,不阻塞)
task = client.submit("https://example.com", width=1280, height=720)
print(f"taskId: {task['taskId']}")
# ... 做其他事情 ...
# 轮询直到完成
result = client.poll(task["taskId"], timeout=60, interval=1)
print(f"imageUrl: {result['imageUrl']}")
错误处理
from songzhiyun import SongzhiClient, SongzhiError
try:
result = client.screenshot("https://example.com")
except SongzhiError as e:
print(f"错误码: {e.code}, 消息: {e.message}")
错误码说明:
| 错误码 | 说明 |
|---|---|
| 1001 | 参数错误或资源不存在 |
| 1002 | 缺少认证信息 |
| 1003 | 本月配额已用完 |
| 1004 | 并发请求超限 |
| 1006 | 请求过于频繁 |
| 5000 | 服务器内部错误 |
相关链接
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
songzhiyun-0.1.0.tar.gz
(3.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file songzhiyun-0.1.0.tar.gz.
File metadata
- Download URL: songzhiyun-0.1.0.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd8cb1d3f589de5b83a59951fec8ba70b28a8405360c6a1460aa2995a51d28f1
|
|
| MD5 |
f2de25bd1738dde6aa78d76170c76294
|
|
| BLAKE2b-256 |
298a60889d918fd0731740892900b5df3c3502c77acda97282cca1f2854bc342
|
File details
Details for the file songzhiyun-0.1.0-py3-none-any.whl.
File metadata
- Download URL: songzhiyun-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
14b5006a00185574340d9c70a24cd8f7b5e34ff66c0cee24908ad936f680c701
|
|
| MD5 |
62f1ae9aa905c55943ef518d7a4b10cd
|
|
| BLAKE2b-256 |
6ba8eb1276cf14108067b2daf73497977fd629abe76531e5798e7c40c8fbcd75
|