From 5735acce4c0d8bef021fa92da019b036cf90c381 Mon Sep 17 00:00:00 2001 From: LeafYeeXYZ Date: Wed, 25 Dec 2024 21:26:06 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=B9=E5=8F=98=E6=8A=A2=E8=AF=BE?= =?UTF-8?q?=E6=97=B6=E6=A3=80=E7=B4=A2=E6=8C=89=E5=BC=80=E8=AF=BE=E8=AE=A1?= =?UTF-8?q?=E5=88=92=E9=80=89=E8=AF=BE=E7=8F=AD=E5=8F=B7=E7=9A=84=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- catch.go | 92 ++++++++++++++++++++++-------- frontend/src/components/Header.tsx | 2 +- 2 files changed, 70 insertions(+), 24 deletions(-) diff --git a/catch.go b/catch.go index 74574b9..d4cff77 100644 --- a/catch.go +++ b/catch.go @@ -388,42 +388,36 @@ func (a *App) CatchCourseMaj(speed int, studentID string, password string, cours iiframe := page.Frames()[2] iiiframe := iiframe.FrameLocator("#frmReport") - // 输入班号 - ele = iiframe.Locator("#txt_skbjdm") - err = ele.Fill(classID) - if err != nil { errCh <- err; return } - - // 点击 "检索" - ele = iiframe.Locator("#btnQry") - err = ele.Click() - if err != nil { errCh <- err; return } + // ------ 2024.12.25 ------ + // 不再通过输入班号来检索课程, 而是直接依次检索 DOM + // ------------------------ // 等待加载 iiframe.WaitForLoadState(playwright.FrameWaitForLoadStateOptions{ State: playwright.LoadStateNetworkidle, }) - time.Sleep(time.Duration(speed) * time.Millisecond) - - // 可选人数 - ele = iiiframe.Locator("#tr0_kxrs") + + // 检索课程 + eleIndex := 0 count = 0 for { - if count > 15000 { - runtime.EventsEmit(a.ctx, "currentStatus", fmt.Sprintf("课程 %s 网络超时或可选人数为零", courseID)) - // runtime.EventsEmit(a.ctx, "importantStatus", fmt.Sprintf("课程 %s 网络超时或可选人数为零", courseID)) 在错误处理时发出 - errCh <- fmt.Errorf("课程 %s 网络超时或可选人数为零", courseID) - return - } + // 班号 + ele = iiiframe.Locator(fmt.Sprintf("#tr%d_curent_skbjdm", eleIndex)) if exists, _ := ele.IsVisible(); exists { - // 检查是否可选人数为 0 + // 如果不是给定的班号, 则继续检索 + if text, _ := ele.InnerText(); text != classID { + eleIndex++ + continue + } + // 如果是给定的班号, 则检查是否可选人数为 0 + ele = iiiframe.Locator(fmt.Sprintf("#tr%d_kxrs", eleIndex)) if text, _ := ele.InnerText(); text == "0" { runtime.EventsEmit(a.ctx, "currentStatus", fmt.Sprintf("课程 %s 可选人数为零", courseID)) - // runtime.EventsEmit(a.ctx, "importantStatus", fmt.Sprintf("课程 %s 可选人数为零", courseID)) 在错误处理时发出 errCh <- fmt.Errorf("课程 %s 可选人数为零", courseID) return } else { - // 勾选 - ele = iiiframe.Locator("#tr0_ischk input") + // 勾选 + ele = iiiframe.Locator(fmt.Sprintf("#tr%d_ischk input", eleIndex)) err = ele.Click() if err != nil { errCh <- err; return } break @@ -432,9 +426,61 @@ func (a *App) CatchCourseMaj(speed int, studentID string, password string, cours runtime.EventsEmit(a.ctx, "currentStatus", fmt.Sprintf("等待检索课程 %s 结果...", courseID)) time.Sleep(time.Duration(speed) * time.Millisecond) count += speed + if count > 15000 { + runtime.EventsEmit(a.ctx, "currentStatus", fmt.Sprintf("课程 %s 网络超时", courseID)) + errCh <- fmt.Errorf("课程 %s 网络超时", courseID) + return + } } } + // // 输入班号 + // ele = iiframe.Locator("#txt_skbjdm") + // err = ele.Fill(classID) + // if err != nil { errCh <- err; return } + + // // 点击 "检索" + // ele = iiframe.Locator("#btnQry") + // err = ele.Click() + // if err != nil { errCh <- err; return } + + // // 等待加载 + // iiframe.WaitForLoadState(playwright.FrameWaitForLoadStateOptions{ + // State: playwright.LoadStateNetworkidle, + // }) + // time.Sleep(time.Duration(speed) * time.Millisecond) + + // // 可选人数 + // ele = iiiframe.Locator("#tr0_kxrs") + // count = 0 + // for { + // if count > 15000 { + // runtime.EventsEmit(a.ctx, "currentStatus", fmt.Sprintf("课程 %s 网络超时或可选人数为零", courseID)) + // // runtime.EventsEmit(a.ctx, "importantStatus", fmt.Sprintf("课程 %s 网络超时或可选人数为零", courseID)) 在错误处理时发出 + // errCh <- fmt.Errorf("课程 %s 网络超时或可选人数为零", courseID) + // return + // } + // if exists, _ := ele.IsVisible(); exists { + // // 检查是否可选人数为 0 + // if text, _ := ele.InnerText(); text == "0" { + // runtime.EventsEmit(a.ctx, "currentStatus", fmt.Sprintf("课程 %s 可选人数为零", courseID)) + // // runtime.EventsEmit(a.ctx, "importantStatus", fmt.Sprintf("课程 %s 可选人数为零", courseID)) 在错误处理时发出 + // errCh <- fmt.Errorf("课程 %s 可选人数为零", courseID) + // return + // } else { + // // 勾选 + // ele = iiiframe.Locator("#tr0_ischk input") + // err = ele.Click() + // if err != nil { errCh <- err; return } + // break + // } + // } else { + // runtime.EventsEmit(a.ctx, "currentStatus", fmt.Sprintf("等待检索课程 %s 结果...", courseID)) + // time.Sleep(time.Duration(speed) * time.Millisecond) + // count += speed + // } + // } + // 点击 "确定" ele = iiframe.Locator("#btnSubmit") err = ele.Click() diff --git a/frontend/src/components/Header.tsx b/frontend/src/components/Header.tsx index 667d4f9..b0a1aa4 100644 --- a/frontend/src/components/Header.tsx +++ b/frontend/src/components/Header.tsx @@ -41,7 +41,7 @@ export function Header() { className='w-full h-full flex items-center justify-start text-sm gap-2 pl-3' > 小鸦抢课 - 2.0.3 + 2.1.0 {systemStatus}