You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

71 lines
1.8 KiB

#!/usr/bin/env python3
"""
简单的网站截图脚本 - 使用系统 Chromium + xvfb
"""
import subprocess
import sys
from datetime import datetime
import os
def take_screenshot(url, output_path=None):
"""
截取网站截图
"""
if output_path is None:
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
output_path = f"/root/.openclaw/workspace/screenshot_{timestamp}.png"
print(f"正在打开: {url}")
# 使用 xvfb-run 来运行 Chromium headless
cmd = [
"xvfb-run",
"-a",
"chromium-browser",
"--headless",
"--no-sandbox",
"--disable-gpu",
"--disable-dev-shm-usage",
f"--screenshot={output_path}",
"--window-size=1920,1080",
url
]
print(f"执行命令: {' '.join(cmd)}")
try:
result = subprocess.run(
cmd,
capture_output=True,
text=True,
timeout=60
)
if result.returncode == 0:
print(f"截图已保存: {output_path}")
if os.path.exists(output_path):
size = os.path.getsize(output_path)
print(f"文件大小: {size} bytes")
return output_path
else:
print(f"错误: {result.stderr}")
return None
except subprocess.TimeoutExpired:
print("超时!")
return None
except Exception as e:
print(f"错误: {e}")
return None
if __name__ == "__main__":
if len(sys.argv) < 2:
print("使用方法: python screenshot_simple.py <url> [output_path]")
print("示例: python screenshot_simple.py https://kirkify.net")
sys.exit(1)
url = sys.argv[1]
output_path = sys.argv[2] if len(sys.argv) > 2 else None
take_screenshot(url, output_path)