From 235d22a4c092e3db0c15b78d51842d6530d780b1 Mon Sep 17 00:00:00 2001 From: lixiangwuxian Date: Sun, 20 Oct 2024 01:27:15 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BF=AE=E6=94=B9=E7=BD=91?= =?UTF-8?q?=E9=A1=B5=E4=B8=BA=E8=BF=9C=E7=A8=8B=E6=89=A7=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- util/web_page_shot.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/web_page_shot.go b/util/web_page_shot.go index 3a32828..7f96c63 100644 --- a/util/web_page_shot.go +++ b/util/web_page_shot.go @@ -15,9 +15,10 @@ import ( // ScreenshotURL 截图函数:传入网址、输出路径、宽高、四个边距和等待的元素 ID func ScreenshotURL(url, output string, width, height int, marginTop, marginBottom, marginRight, marginLeft int, waitClass string) error { + // 创建一个上下文,连接到 Docker 中运行的 headless-shell 实例 remoteAllocatorCtx, cancel := chromedp.NewRemoteAllocator( - context.Background(), "ws://127.0.0.1:9222/json/ws", + context.Background(), "ws://100.124.180.117:9222/json/ws", ) defer cancel() @@ -69,7 +70,6 @@ func ScreenshotURL(url, output string, width, height int, marginTop, marginBotto if err := chromedp.Run(ctx, network.SetExtraHTTPHeaders(network.Headers(headers))); err != nil { return fmt.Errorf("设置请求头失败: %w", err) } - // 执行任务:打开网页并截图 err := chromedp.Run(ctx, chromedp.Navigate(url), // 打开网页