130 lines
4.5 KiB
Go
130 lines
4.5 KiB
Go
package method
|
||
|
||
import (
|
||
"bufio"
|
||
"dt_automate/tool"
|
||
"fmt"
|
||
"log"
|
||
"os"
|
||
|
||
"github.com/playwright-community/playwright-go"
|
||
)
|
||
|
||
func ZWW_TSGZ() {
|
||
// 启动 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.20")
|
||
if err != nil {
|
||
log.Fatalf("could not go to the page: %v", err)
|
||
}
|
||
|
||
// page.WaitForTimeout(2000)
|
||
// page.Locator(`.verification-item .el-image`).Screenshot(playwright.LocatorScreenshotOptions{
|
||
// Path: playwright.String("img/capt.png"),
|
||
// })
|
||
|
||
a := page.Locator(`.el-input__inner`)
|
||
|
||
// result := wtch_ocr.OcrDefault("img/capt.png")
|
||
// if len(result.OcrResponse[0].Text) == 4 {
|
||
// log.Println("读取验证码:", result.OcrResponse[0].Text)
|
||
// a.Nth(2).Fill(result.OcrResponse[0].Text)
|
||
// } else {
|
||
// page.WaitForTimeout(500)
|
||
// page.Locator(".verification-item .el-image .el-image__inner").Click()
|
||
// }
|
||
|
||
// Screenshot(playwright.PageScreenshotOptions{})
|
||
// (playwright.PageScreenshotOptions{
|
||
// Path: playwright.String("img/capg.png"),
|
||
// FullPage: playwright.Bool(true),
|
||
// })
|
||
//输入
|
||
a.Nth(0).Fill(tool.KeyStr("pA1RJlFFWubvxI242Y2hTg7oOWVxBP3C8SZlcd4aiyoQPEq1ZGQZkVQn1Hams2LEv0sEzEmRjkFxWzpUm/B0fZkGzSJc7iecCODG+MdssNuxEh3ARWQaX+rXq1LWjL4YB5tqev18P35zXkJhZpyhqq3A9hE9T2XWwK8l6BlnxzK4KSlp+3tQ/gNtBosAME+XpYSRavJOl1MDeIVfogcYrHpx5IITLyz3koCkN7N9ban5RcPxT+jfQGYkCUbnAMsZGcbDfbTvxVP9k0huGVsGpnEkVt4G2vLtO96XTUc8/fXCmLHPxcPEjhGPMukXi7avBWiG/yaKjNxzPXmtLeioNA=="))
|
||
page.WaitForTimeout(500)
|
||
a.Nth(1).Fill(tool.KeyStr("cWhJA/oHtrWpmTCvy2+IlZD2UoriOFGWfoNobAZ7sZwkQ6fnd0pbxloFRV7mVPkPtEkCg4Z51K5u+4fsgXDVLN/Oo4BeoMFNJj7uz7A3v2ar7lOvYmPbnAT7ZvM109UvP5qGe+GfR+lXTC2H9PxLm+pdqBTySbT2u9DwAnhWIGR1LSbnDCFnoSgKgSoUKqUCsW6VbI32pLPVGrvrI7iFNGlZ3Ac0d/33klby5BcR8q3TYJaQbb+TZ6IjZto6gfiOObR6RwmmIw4kTw/y9iYukECce//OQo0Y5TvL1EIL+fNElwAy/AVvyAGP8ba74gALwS8fh+3WO6+sMv2NaSYRrw=="))
|
||
reader := bufio.NewReader(os.Stdin)
|
||
fmt.Print("请输入验证码:")
|
||
input, _ := reader.ReadString('\n')
|
||
a.Nth(2).Fill(input)
|
||
page.WaitForTimeout(500)
|
||
//点击同意
|
||
if err := page.Locator(`.el-checkbox__inner`).Click(); err != nil {
|
||
log.Println(err)
|
||
}
|
||
//登录
|
||
page.WaitForTimeout(1000)
|
||
if err := page.Locator(`.el-button.el-button--primary.el-button--large.login-button`).Click(); err != nil {
|
||
log.Println(err)
|
||
}
|
||
page.WaitForTimeout(500)
|
||
_, err = page.Goto("https://11.1.65.20/#/threatCenter/asset")
|
||
page.WaitForTimeout(1000)
|
||
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.Locator(`.el-range-input`).Nth(0).Click()
|
||
page.WaitForTimeout(500)
|
||
page.Locator(`.el-picker-panel__shortcut`).Nth(0).Click()
|
||
page.WaitForTimeout(300)
|
||
page.Locator(`.display-inline-flex.align-items-center.justify-content-end.advanced-search-wrapper .el-button.el-button--primary`).Click()
|
||
page.WaitForTimeout(1000)
|
||
tool.Jietu("img/zww_tsgz.png")
|
||
page.WaitForTimeout(2000)
|
||
// 获取页面标题
|
||
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)
|
||
}
|