118 lines
4.5 KiB
Go
118 lines
4.5 KiB
Go
package method
|
||
|
||
import (
|
||
"dt_automate/tool"
|
||
"log"
|
||
|
||
"github.com/playwright-community/playwright-go"
|
||
)
|
||
|
||
func HW_FAC1() {
|
||
// 启动 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.2.65.19/", playwright.PageGotoOptions{WaitUntil: playwright.WaitUntilStateDomcontentloaded})
|
||
if err != nil {
|
||
log.Fatalf("could not go to the page: %v", err)
|
||
}
|
||
page.WaitForTimeout(2000)
|
||
//输入
|
||
if err := page.Locator(`.cover-input input[placeholder="账号"]`).Fill(tool.KeyStr("gyZxYqy9Bjl0Zh09JWG+pemEJWdig+oxxIck8jgq+gKKFEYMBQJpY6rLlhhyC6qU4N4aPP+BkErlx8vD2/5rUDpOWIpnLq0yUHPlOR1ZrrtNJ4uA39goVnDYSn4Qwg3v3He5rdzkj25Xmt7LMScAWdMt+j2QdGKnRtMLOkkGoPQpsp+2ft4b7jxD90Hx30g1BM7Hj4QqtlEpHbR6qjEY6rQyTppJ2+WGGpNj5dIl/QAFSZpFR1iLJGxrXkAmzCzz2S+hveJ+5IhZLsDKfgFXR2VWZdRXdAdjaNzCK/4H4WQp19ZA9cxjGieUOFHBe/Hz49O0RYQnj/8Udd9HDmElMA==")); err != nil {
|
||
log.Fatalf("could not fill input: %v", err)
|
||
}
|
||
if err := page.Locator(`.cover-pwd input[placeholder="密码"]`).Fill(tool.KeyStr("IUe1xEFLjpjQsPfJO4/q6hHLoazsJri3uRCg2If9V7D69nHrmeu48Mveyju19RV0G5g31Td7EX0JnAuT08LtbgVVDFq8ZY9oPi7kUIMdhwadL1hiPpI3/UNQ4ZD8MVjUxb5NRoRs34TQd/pQgiHJEueGulJFjLWHw2vCya/MYFUJf+qezMHdhTBbx7QNxs6R3XkCN6G5ksVWgBrNU239INlRtNDo5eDWk8W7wO64Dh1tnmhIOZ3Kvn3Xdk07y9nbg+FtAj9R5okQWMzhlhvmqrUeJJVIxywmZhZ2H2Q9kcf7zq3DeaRDUQApIdqdup6EriSqMdMEQ4muZAi/+cS8mw==")); err != nil {
|
||
log.Fatalf("could not fill input: %v", err)
|
||
}
|
||
page.WaitForTimeout(500)
|
||
//登录
|
||
if err := page.Locator(".login-btn").Click(); err != nil {
|
||
log.Fatalf("could not click button: %v", err)
|
||
}
|
||
page.WaitForTimeout(1000)
|
||
page.Locator(`.nav-two a[title="日志中心"]`).Click()
|
||
page.WaitForTimeout(2000)
|
||
// 执行 JavaScript 代码
|
||
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(500)
|
||
// page.Screenshot(playwright.PageScreenshotOptions{
|
||
// Path: playwright.String("img/afc2000_1.png"),
|
||
// })
|
||
tool.Jietu("img/afc2000_1.png")
|
||
page.Locator(`#OneLevel0_TwoLevel3 a[href="#"]`).Click()
|
||
page.WaitForTimeout(2000)
|
||
// 定位 iframe
|
||
// 等待 iframe 加载完成
|
||
// _, err = page.WaitForSelector(".panel-body.panel-body-noheader.panel-body-noborder iframe")
|
||
// if err != nil {
|
||
// log.Fatalf("等待 iframe 加载失败: %v", err)
|
||
// }
|
||
// page.Locator(`#peak_value .content input[value="查询"]`).Click()
|
||
// 定位 iframe 并操作内部元素
|
||
iframeLocator, _ := page.QuerySelectorAll("iframe")
|
||
iframe, _ := iframeLocator[1].ContentFrame()
|
||
iframe.Locator(`#peak_value input[value="查询"]`).Click()
|
||
page.WaitForTimeout(500)
|
||
iframe.Locator(`#peak_value input[value="2"]`).Click()
|
||
page.WaitForTimeout(1000)
|
||
// page.Screenshot(playwright.PageScreenshotOptions{
|
||
// Path: playwright.String("img/afc2000_2.png"),
|
||
// FullPage: playwright.Bool(true),
|
||
// })
|
||
tool.Jietu("img/afc2000_2.png")
|
||
// 获取页面标题
|
||
title, err := page.Title()
|
||
if err != nil {
|
||
log.Fatalf("could not get title: %v", err)
|
||
}
|
||
log.Printf("Page title is: %s\n", title)
|
||
page.WaitForTimeout(5000)
|
||
// StartBlocker()
|
||
}
|