2025-02-27 18:37:03 +08:00
|
|
|
|
package method
|
|
|
|
|
|
|
|
|
|
import (
|
2025-03-04 17:40:37 +08:00
|
|
|
|
"bufio"
|
2025-02-27 18:37:03 +08:00
|
|
|
|
"dt_automate/tool"
|
|
|
|
|
"fmt"
|
|
|
|
|
"log"
|
2025-03-04 17:40:37 +08:00
|
|
|
|
"os"
|
2025-02-27 18:37:03 +08:00
|
|
|
|
|
|
|
|
|
"github.com/playwright-community/playwright-go"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func ZWWW_BAOLJ() {
|
|
|
|
|
|
|
|
|
|
// 启动 Playwright
|
|
|
|
|
pw, err := playwright.Run()
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("could not start Playwright: %v", err)
|
|
|
|
|
}
|
|
|
|
|
defer pw.Stop()
|
|
|
|
|
|
|
|
|
|
// 启动浏览器(Chromium)
|
|
|
|
|
browser, err := pw.Chromium.Launch(playwright.BrowserTypeLaunchOptions{
|
|
|
|
|
Headless: playwright.Bool(false), // 设置为 false 以显示浏览器界面
|
|
|
|
|
Args: []string{
|
|
|
|
|
"--ignore-certificate-errors", // 忽略证书错误[^28^][^29^]
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("could not launch browser: %v", err)
|
|
|
|
|
}
|
|
|
|
|
defer browser.Close()
|
|
|
|
|
|
|
|
|
|
// 创建一个新页面
|
|
|
|
|
page, err := browser.NewPage()
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("could not create page: %v", err)
|
|
|
|
|
}
|
|
|
|
|
// 设置浏览器窗口大小
|
|
|
|
|
err = page.SetViewportSize(1920, 1080) // 宽度为 1200px,高度为 800px
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("无法设置浏览器窗口大小: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 导航到指定网址
|
|
|
|
|
_, err = page.Goto("https://11.1.65.22/webui/login", playwright.PageGotoOptions{WaitUntil: playwright.WaitUntilStateDomcontentloaded})
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("could not go to the page: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
page.WaitForTimeout(4000)
|
|
|
|
|
page.Locator(`#inputUserName`).Fill("lichao")
|
|
|
|
|
page.Locator(`#inputPassword`).Fill("Lc753951!!")
|
|
|
|
|
|
2025-03-04 17:40:37 +08:00
|
|
|
|
reader := bufio.NewReader(os.Stdin)
|
2025-02-27 18:37:03 +08:00
|
|
|
|
fmt.Print("是否需要输入验证码1允许,0跳过:")
|
2025-03-04 17:40:37 +08:00
|
|
|
|
name, _ := reader.ReadString('\n')
|
2025-02-27 18:37:03 +08:00
|
|
|
|
if name == "1" {
|
2025-03-04 17:40:37 +08:00
|
|
|
|
|
|
|
|
|
reader := bufio.NewReader(os.Stdin)
|
2025-02-27 18:37:03 +08:00
|
|
|
|
fmt.Print("请输入验证码:")
|
2025-03-04 17:40:37 +08:00
|
|
|
|
input, _ := reader.ReadString('\n')
|
|
|
|
|
page.Locator(`#inputCaptcha`).Fill(input)
|
2025-02-27 18:37:03 +08:00
|
|
|
|
}
|
|
|
|
|
page.Locator(`.loginFormButtonLogin`).Click()
|
2025-03-04 17:40:37 +08:00
|
|
|
|
reader1 := bufio.NewReader(os.Stdin)
|
2025-02-27 18:37:03 +08:00
|
|
|
|
fmt.Print("请输入OTA口令:")
|
2025-03-04 17:40:37 +08:00
|
|
|
|
input, _ := reader1.ReadString('\n')
|
|
|
|
|
page.Locator(`.form-group.form-control.dynamic_code`).Nth(0).Locator(`input[name="token"]`).Fill(input)
|
2025-02-27 18:37:03 +08:00
|
|
|
|
//登录
|
2025-03-04 17:40:37 +08:00
|
|
|
|
page.Locator(`.form-group`).Nth(7).Locator(`button`).Nth(2).Click()
|
|
|
|
|
page.WaitForTimeout(500)
|
|
|
|
|
page.Goto("https://11.1.65.22/webui/#/business/audits/event/log/login", playwright.PageGotoOptions{WaitUntil: playwright.WaitUntilStateDomcontentloaded})
|
2025-02-27 18:37:03 +08:00
|
|
|
|
page.WaitForTimeout(2000)
|
|
|
|
|
page.Evaluate(`
|
|
|
|
|
const now = new Date();
|
|
|
|
|
const year = now.getFullYear();
|
|
|
|
|
const month = (now.getMonth() + 1).toString().padStart(2, '0');
|
|
|
|
|
const day = now.getDate().toString().padStart(2, '0');
|
|
|
|
|
const hours = now.getHours().toString().padStart(2, '0');
|
|
|
|
|
const minutes = now.getMinutes().toString().padStart(2, '0');
|
|
|
|
|
const seconds = now.getSeconds().toString().padStart(2, '0');
|
|
|
|
|
const timestamp = year+"-"+month+"-"+day +" "+ hours+":"+minutes+":"+seconds;
|
|
|
|
|
const div = document.createElement('div');
|
|
|
|
|
div.style.position = 'fixed';
|
|
|
|
|
div.style.bottom = '10px';
|
|
|
|
|
div.style.right = '10px';
|
|
|
|
|
div.style.color = 'white';
|
|
|
|
|
div.style.backgroundColor = 'black';
|
|
|
|
|
div.style.padding = '5px';
|
|
|
|
|
div.style.borderRadius = '5px';
|
|
|
|
|
div.textContent = timestamp;
|
|
|
|
|
document.body.appendChild(div);
|
|
|
|
|
`, nil)
|
|
|
|
|
page.WaitForTimeout(1000)
|
|
|
|
|
tool.Jietu("img/zww_baolj.png")
|
|
|
|
|
// 获取页面标题
|
|
|
|
|
title, err := page.Title()
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("could not get title: %v", err)
|
|
|
|
|
}
|
|
|
|
|
log.Printf("Page title is: %s\n", title)
|
|
|
|
|
|
|
|
|
|
// StartBlocker()
|
|
|
|
|
page.WaitForTimeout(5000)
|
|
|
|
|
}
|