|
@@ -72,6 +72,7 @@ func (self *ToolController) GetHaibaoWithGoogle() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
beego.BeeLogger.Info("GetHaibaoWithGoogle start url=[%s]", maskURLForLog(decodedUri))
|
|
beego.BeeLogger.Info("GetHaibaoWithGoogle start url=[%s]", maskURLForLog(decodedUri))
|
|
|
|
|
+ renderURL := appendHaibaoCacheBuster(decodedUri)
|
|
|
//title := self.GetString("title")
|
|
//title := self.GetString("title")
|
|
|
// 创建上下文
|
|
// 创建上下文
|
|
|
ctx, cancel := chromedp.NewContext(context.Background(), chromedp.WithErrorf(chromedpErrorLogf))
|
|
ctx, cancel := chromedp.NewContext(context.Background(), chromedp.WithErrorf(chromedpErrorLogf))
|
|
@@ -84,7 +85,7 @@ func (self *ToolController) GetHaibaoWithGoogle() {
|
|
|
// 运行任务(导航到网页,并捕获屏幕截图)
|
|
// 运行任务(导航到网页,并捕获屏幕截图)
|
|
|
err = chromedp.Run(ctx,
|
|
err = chromedp.Run(ctx,
|
|
|
chromedp.EmulateViewport(1400, 800), // 设置视口宽度为 1400,高度为 800
|
|
chromedp.EmulateViewport(1400, 800), // 设置视口宽度为 1400,高度为 800
|
|
|
- chromedp.Navigate(decodedUri), // 替换为你想截图的网页地址
|
|
|
|
|
|
|
+ chromedp.Navigate(renderURL), // 替换为你想截图的网页地址
|
|
|
chromedp.WaitReady("body", chromedp.ByQuery),
|
|
chromedp.WaitReady("body", chromedp.ByQuery),
|
|
|
)
|
|
)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -118,6 +119,7 @@ func (self *ToolController) GetOtherHaibaoWithGoogle() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
beego.BeeLogger.Info("GetOtherHaibaoWithGoogle start url=[%s]", maskURLForLog(decodedUri))
|
|
beego.BeeLogger.Info("GetOtherHaibaoWithGoogle start url=[%s]", maskURLForLog(decodedUri))
|
|
|
|
|
+ renderURL := appendHaibaoCacheBuster(decodedUri)
|
|
|
//title := self.GetString("title")
|
|
//title := self.GetString("title")
|
|
|
// 创建上下文
|
|
// 创建上下文
|
|
|
ctx, cancel := chromedp.NewContext(context.Background(), chromedp.WithErrorf(chromedpErrorLogf))
|
|
ctx, cancel := chromedp.NewContext(context.Background(), chromedp.WithErrorf(chromedpErrorLogf))
|
|
@@ -130,7 +132,7 @@ func (self *ToolController) GetOtherHaibaoWithGoogle() {
|
|
|
// 运行任务(导航到网页,并捕获屏幕截图)
|
|
// 运行任务(导航到网页,并捕获屏幕截图)
|
|
|
err = chromedp.Run(ctx,
|
|
err = chromedp.Run(ctx,
|
|
|
chromedp.EmulateViewport(1400, 800), // 设置视口宽度为 1400,高度为 800
|
|
chromedp.EmulateViewport(1400, 800), // 设置视口宽度为 1400,高度为 800
|
|
|
- chromedp.Navigate(decodedUri), // 替换为你想截图的网页地址
|
|
|
|
|
|
|
+ chromedp.Navigate(renderURL), // 替换为你想截图的网页地址
|
|
|
chromedp.WaitReady("body", chromedp.ByQuery), // 等待页面的 <body> 元素加载完成
|
|
chromedp.WaitReady("body", chromedp.ByQuery), // 等待页面的 <body> 元素加载完成
|
|
|
)
|
|
)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -219,6 +221,17 @@ func chromedpErrorLogf(format string, args ...interface{}) {
|
|
|
beego.BeeLogger.Error("chromedp error: %s", msg)
|
|
beego.BeeLogger.Error("chromedp error: %s", msg)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func appendHaibaoCacheBuster(rawURL string) string {
|
|
|
|
|
+ u, err := url.Parse(rawURL)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return rawURL
|
|
|
|
|
+ }
|
|
|
|
|
+ q := u.Query()
|
|
|
|
|
+ q.Set("_haibao_ts", fmt.Sprintf("%d", time.Now().UnixNano()))
|
|
|
|
|
+ u.RawQuery = q.Encode()
|
|
|
|
|
+ return u.String()
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
func captureNonBlankScreenshot(ctx context.Context, safeURL string, quality int) ([]byte, error) {
|
|
func captureNonBlankScreenshot(ctx context.Context, safeURL string, quality int) ([]byte, error) {
|
|
|
waitPlan := []time.Duration{
|
|
waitPlan := []time.Duration{
|
|
|
3 * time.Second,
|
|
3 * time.Second,
|