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), // 打开网页