Skip to content

Commit 6700b95

Browse files
committed
优化 catch_http 2022-09-11
1 parent 7577b33 commit 6700b95

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

spider/catch_http.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,31 @@ func GenerateUUID() string {
8080
return uuid.NewV4().String()
8181
}
8282

83-
/*执行截图*/
83+
/*
84+
执行截图
85+
--remote-debugging-port=9222
86+
参考:https://github.com/chromedp/chromedp/issues/1131
87+
88+
chromedp.Evaluate(js, &height), 返回最后一行js语句的结果
89+
*/
8490
func DoFullScreenshot(url, path string) bool {
8591
opts := append(chromedp.DefaultExecAllocatorOptions[:],
86-
chromedp.Flag("headless", true),
92+
chromedp.NoDefaultBrowserCheck,
93+
chromedp.Flag("headless", false),
8794
chromedp.Flag("ignore-certificate-errors", true),
95+
chromedp.Flag("disable-web-security", true),
96+
chromedp.Flag("disable-extensions", true), //开启插件支持
97+
chromedp.Flag("disable-default-apps", true),
98+
chromedp.Flag("disable-gpu", true), //开启 gpu 渲染
99+
chromedp.Flag("hide-scrollbars", true),
100+
chromedp.Flag("mute-audio", true),
101+
chromedp.Flag("no-sandbox", true),
102+
chromedp.Flag("no-default-browser-check", true),
103+
chromedp.NoFirstRun, //设置网站不是首次运行
88104
chromedp.WindowSize(MaxWidth, MinHeight),
105+
chromedp.Flag("blink-settings", "imagesEnabled=true"),
106+
chromedp.Flag("enable-automation", false),
107+
chromedp.UserAgent("Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36"),
89108
)
90109
allocCtx, cancel := chromedp.NewExecAllocator(context.Background(), opts...)
91110
defer cancel()

0 commit comments

Comments
 (0)