refactor: 修改网页为远程执行
This commit is contained in:
parent
66d0d683e8
commit
235d22a4c0
@ -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), // 打开网页
|
||||
|
Loading…
x
Reference in New Issue
Block a user