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.
 
 
 
 
 

78 lines
2.1 KiB

#!/usr/bin/env python3
"""
最终的网站截图脚本 - 直接用 Chromium headless
"""
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"screenshot_{timestamp}.png"
print(f"正在打开: {url}")
# 直接用 Chromium headless 模式
cmd = [
"chromium-browser",
"--headless=new",
"--no-sandbox",
"--disable-gpu",
"--disable-dev-shm-usage",
"--disable-software-rasterizer",
f"--screenshot={output_path}",
"--window-size=1920,1080",
"--virtual-time-budget=10000",
url
]
print(f"执行命令: {' '.join(cmd)}")
try:
result = subprocess.run(
cmd,
capture_output=True,
text=True,
timeout=90
)
print(f"返回码: {result.returncode}")
if result.stdout:
print(f"标准输出: {result.stdout}")
if result.stderr:
print(f"标准错误: {result.stderr}")
if result.returncode == 0 and os.path.exists(output_path):
size = os.path.getsize(output_path)
print(f"✅ 成功!截图已保存: {output_path} ({size} bytes)")
return output_path
else:
print("❌ 失败")
return None
except subprocess.TimeoutExpired:
print("⏰ 超时!")
return None
except Exception as e:
print(f"❌ 错误: {e}")
import traceback
traceback.print_exc()
return None
if __name__ == "__main__":
if len(sys.argv) < 2:
print("使用方法: python screenshot_final.py <url> [output_path]")
print("示例: python screenshot_final.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)