107 lines
3.9 KiB
Go
107 lines
3.9 KiB
Go
package method
|
||
|
||
import (
|
||
"bufio"
|
||
"dt_automate/tool"
|
||
"fmt"
|
||
"log"
|
||
"os"
|
||
|
||
"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(tool.KeyStr("tEGZ+KBYPVlup4kvg35r0/0LHGs3Y8D3sxgbSbw/q51TodzFA6owWejvE6CA3HnYqPJ5EB1Ws99iTzE8YFMmAp9JHefcqcjTd61ViNZMz6aQ9GnGAXcfD5ajEEjnaO5JiFkdwhwjuh73KO3B5evxzJ9ft31/8vos7o1HioBE9W97iOWfMALqN2/DpISk6VXqBcyz4a9OB6j3cU1dDoM+mqct5ES+QucTPdy64aGQZ8bBGiGHgl6CTZaUmnOMEaZROfuIid9cIRO5/zrX1Kk00oiXxj/kDUiclqcZUAZNhQp8OUDnICn7nRxCfpO6jtjWw24PAdx5BQxz41tScVvQNw=="))
|
||
page.Locator(`#inputPassword`).Fill(tool.KeyStr("GRK8wZZe3HEWv3YcKh8ckDncZsZq6xUDpcQn5IhetQ8zzu2IjVk8EpZZ9LbScryUMjWKBz2gtRzlb7NLkfjZ0uLmAvnkVL2D8grWzQ5mLD1UwgSl8NYneyktPAivBP9nBO1oQrWgcH5o0Qi9aHIDRP3Stx7Xi3OmD7/1sCdz3EWMDD5r8rqsznXOts5pQXw8vDFA4xZb64nv8/uqwUO0ovEgDMmbVHdi1/PVuhWOIFqmuPPacFiGusG5H8zguTMFRXB++J7Dp3RoQnLFsaURj+bpaFzJzVbiR4IcyQ+qMPJ9Y4ChGIEwa7J1u9BUu2yKs1PJMdUHJo7ntMwQKGh8cQ=="))
|
||
|
||
reader := bufio.NewReader(os.Stdin)
|
||
fmt.Print("是否需要输入验证码1允许,0跳过:")
|
||
name, _ := reader.ReadString('\n')
|
||
if name == "1" {
|
||
|
||
reader := bufio.NewReader(os.Stdin)
|
||
fmt.Print("请输入验证码:")
|
||
input, _ := reader.ReadString('\n')
|
||
page.Locator(`#inputCaptcha`).Fill(input)
|
||
}
|
||
page.Locator(`.loginFormButtonLogin`).Click()
|
||
reader1 := bufio.NewReader(os.Stdin)
|
||
fmt.Print("请输入OTA口令:")
|
||
input, _ := reader1.ReadString('\n')
|
||
page.Locator(`.form-group.form-control.dynamic_code`).Nth(0).Locator(`input[name="token"]`).Fill(input)
|
||
//登录
|
||
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})
|
||
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)
|
||
}
|