feat: 全屏截图改用管理后台框架
This commit is contained in:
@@ -28,7 +28,7 @@ os.makedirs(SCREENSHOTS_DIR, exist_ok=True)
|
||||
_WKHTMLTOIMAGE_TIMEOUT_SECONDS = int(os.environ.get("WKHTMLTOIMAGE_TIMEOUT_SECONDS", "60"))
|
||||
_WKHTMLTOIMAGE_JS_DELAY_MS = int(os.environ.get("WKHTMLTOIMAGE_JS_DELAY_MS", "3000"))
|
||||
_WKHTMLTOIMAGE_WIDTH = int(os.environ.get("WKHTMLTOIMAGE_WIDTH", "1920"))
|
||||
_WKHTMLTOIMAGE_HEIGHT = int(os.environ.get("WKHTMLTOIMAGE_HEIGHT", "2000"))
|
||||
_WKHTMLTOIMAGE_HEIGHT = int(os.environ.get("WKHTMLTOIMAGE_HEIGHT", "1080"))
|
||||
_WKHTMLTOIMAGE_QUALITY = int(os.environ.get("WKHTMLTOIMAGE_QUALITY", "95"))
|
||||
_WKHTMLTOIMAGE_UA = os.environ.get(
|
||||
"WKHTMLTOIMAGE_USER_AGENT",
|
||||
@@ -86,6 +86,8 @@ def take_screenshot_wkhtmltoimage(
|
||||
output_path: str,
|
||||
cookies_path: str | None = None,
|
||||
proxy_server: str | None = None,
|
||||
run_script: str | None = None,
|
||||
window_status: str | None = None,
|
||||
log_callback=None,
|
||||
) -> bool:
|
||||
wkhtmltoimage_path = _resolve_wkhtmltoimage_path()
|
||||
@@ -122,6 +124,11 @@ def take_screenshot_wkhtmltoimage(
|
||||
if _WKHTMLTOIMAGE_HEIGHT > 0:
|
||||
cmd.extend(["--height", str(_WKHTMLTOIMAGE_HEIGHT)])
|
||||
|
||||
if run_script:
|
||||
cmd.extend(["--run-script", run_script])
|
||||
if window_status:
|
||||
cmd.extend(["--window-status", window_status])
|
||||
|
||||
if cookies_path:
|
||||
cookie_pairs = _select_cookie_pairs(_read_cookie_pairs(cookies_path))
|
||||
if cookie_pairs:
|
||||
@@ -238,6 +245,17 @@ def take_screenshot_for_account(
|
||||
else:
|
||||
bz = 2 # 应读
|
||||
target_url = f"{base}/admin/center.aspx?bz={bz}"
|
||||
index_url = config.ZSGL_INDEX_URL or f"{base}/admin/index.aspx"
|
||||
run_script = (
|
||||
"(function(){"
|
||||
"var f=document.getElementById('mainframe');"
|
||||
"function done(){window.status='ready';}"
|
||||
"if(!f){done();return;}"
|
||||
f"f.src='{target_url}';"
|
||||
"f.onload=function(){setTimeout(done,500);};"
|
||||
"setTimeout(done,4000);"
|
||||
"})();"
|
||||
)
|
||||
|
||||
timestamp = get_beijing_now().strftime("%Y%m%d_%H%M%S")
|
||||
|
||||
@@ -247,10 +265,19 @@ def take_screenshot_for_account(
|
||||
screenshot_filename = f"{username_prefix}_{login_account}_{browse_type}_{timestamp}.jpg"
|
||||
screenshot_path = os.path.join(SCREENSHOTS_DIR, screenshot_filename)
|
||||
|
||||
cookies_for_shot = cookie_path if is_cookie_jar_fresh(cookie_path) else None
|
||||
if take_screenshot_wkhtmltoimage(
|
||||
index_url,
|
||||
screenshot_path,
|
||||
cookies_path=cookies_for_shot,
|
||||
proxy_server=proxy_server,
|
||||
run_script=run_script,
|
||||
window_status="ready",
|
||||
log_callback=custom_log,
|
||||
) or take_screenshot_wkhtmltoimage(
|
||||
target_url,
|
||||
screenshot_path,
|
||||
cookies_path=cookie_path if is_cookie_jar_fresh(cookie_path) else None,
|
||||
cookies_path=cookies_for_shot,
|
||||
proxy_server=proxy_server,
|
||||
log_callback=custom_log,
|
||||
):
|
||||
|
||||
Reference in New Issue
Block a user