Skip to content

Commit 5735acc

Browse files
committed
feat: 改变抢课时检索按开课计划选课班号的方法
1 parent 56bcca0 commit 5735acc

File tree

2 files changed

+70
-24
lines changed

2 files changed

+70
-24
lines changed

catch.go

Lines changed: 69 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -388,42 +388,36 @@ func (a *App) CatchCourseMaj(speed int, studentID string, password string, cours
388388
iiframe := page.Frames()[2]
389389
iiiframe := iiframe.FrameLocator("#frmReport")
390390

391-
// 输入班号
392-
ele = iiframe.Locator("#txt_skbjdm")
393-
err = ele.Fill(classID)
394-
if err != nil { errCh <- err; return }
395-
396-
// 点击 "检索"
397-
ele = iiframe.Locator("#btnQry")
398-
err = ele.Click()
399-
if err != nil { errCh <- err; return }
391+
// ------ 2024.12.25 ------
392+
// 不再通过输入班号来检索课程, 而是直接依次检索 DOM
393+
// ------------------------
400394

401395
// 等待加载
402396
iiframe.WaitForLoadState(playwright.FrameWaitForLoadStateOptions{
403397
State: playwright.LoadStateNetworkidle,
404398
})
405-
time.Sleep(time.Duration(speed) * time.Millisecond)
406-
407-
// 可选人数
408-
ele = iiiframe.Locator("#tr0_kxrs")
399+
400+
// 检索课程
401+
eleIndex := 0
409402
count = 0
410403
for {
411-
if count > 15000 {
412-
runtime.EventsEmit(a.ctx, "currentStatus", fmt.Sprintf("课程 %s 网络超时或可选人数为零", courseID))
413-
// runtime.EventsEmit(a.ctx, "importantStatus", fmt.Sprintf("课程 %s 网络超时或可选人数为零", courseID)) 在错误处理时发出
414-
errCh <- fmt.Errorf("课程 %s 网络超时或可选人数为零", courseID)
415-
return
416-
}
404+
// 班号
405+
ele = iiiframe.Locator(fmt.Sprintf("#tr%d_curent_skbjdm", eleIndex))
417406
if exists, _ := ele.IsVisible(); exists {
418-
// 检查是否可选人数为 0
407+
// 如果不是给定的班号, 则继续检索
408+
if text, _ := ele.InnerText(); text != classID {
409+
eleIndex++
410+
continue
411+
}
412+
// 如果是给定的班号, 则检查是否可选人数为 0
413+
ele = iiiframe.Locator(fmt.Sprintf("#tr%d_kxrs", eleIndex))
419414
if text, _ := ele.InnerText(); text == "0" {
420415
runtime.EventsEmit(a.ctx, "currentStatus", fmt.Sprintf("课程 %s 可选人数为零", courseID))
421-
// runtime.EventsEmit(a.ctx, "importantStatus", fmt.Sprintf("课程 %s 可选人数为零", courseID)) 在错误处理时发出
422416
errCh <- fmt.Errorf("课程 %s 可选人数为零", courseID)
423417
return
424418
} else {
425-
// 勾选
426-
ele = iiiframe.Locator("#tr0_ischk input")
419+
// 勾选
420+
ele = iiiframe.Locator(fmt.Sprintf("#tr%d_ischk input", eleIndex))
427421
err = ele.Click()
428422
if err != nil { errCh <- err; return }
429423
break
@@ -432,9 +426,61 @@ func (a *App) CatchCourseMaj(speed int, studentID string, password string, cours
432426
runtime.EventsEmit(a.ctx, "currentStatus", fmt.Sprintf("等待检索课程 %s 结果...", courseID))
433427
time.Sleep(time.Duration(speed) * time.Millisecond)
434428
count += speed
429+
if count > 15000 {
430+
runtime.EventsEmit(a.ctx, "currentStatus", fmt.Sprintf("课程 %s 网络超时", courseID))
431+
errCh <- fmt.Errorf("课程 %s 网络超时", courseID)
432+
return
433+
}
435434
}
436435
}
437436

437+
// // 输入班号
438+
// ele = iiframe.Locator("#txt_skbjdm")
439+
// err = ele.Fill(classID)
440+
// if err != nil { errCh <- err; return }
441+
442+
// // 点击 "检索"
443+
// ele = iiframe.Locator("#btnQry")
444+
// err = ele.Click()
445+
// if err != nil { errCh <- err; return }
446+
447+
// // 等待加载
448+
// iiframe.WaitForLoadState(playwright.FrameWaitForLoadStateOptions{
449+
// State: playwright.LoadStateNetworkidle,
450+
// })
451+
// time.Sleep(time.Duration(speed) * time.Millisecond)
452+
453+
// // 可选人数
454+
// ele = iiiframe.Locator("#tr0_kxrs")
455+
// count = 0
456+
// for {
457+
// if count > 15000 {
458+
// runtime.EventsEmit(a.ctx, "currentStatus", fmt.Sprintf("课程 %s 网络超时或可选人数为零", courseID))
459+
// // runtime.EventsEmit(a.ctx, "importantStatus", fmt.Sprintf("课程 %s 网络超时或可选人数为零", courseID)) 在错误处理时发出
460+
// errCh <- fmt.Errorf("课程 %s 网络超时或可选人数为零", courseID)
461+
// return
462+
// }
463+
// if exists, _ := ele.IsVisible(); exists {
464+
// // 检查是否可选人数为 0
465+
// if text, _ := ele.InnerText(); text == "0" {
466+
// runtime.EventsEmit(a.ctx, "currentStatus", fmt.Sprintf("课程 %s 可选人数为零", courseID))
467+
// // runtime.EventsEmit(a.ctx, "importantStatus", fmt.Sprintf("课程 %s 可选人数为零", courseID)) 在错误处理时发出
468+
// errCh <- fmt.Errorf("课程 %s 可选人数为零", courseID)
469+
// return
470+
// } else {
471+
// // 勾选
472+
// ele = iiiframe.Locator("#tr0_ischk input")
473+
// err = ele.Click()
474+
// if err != nil { errCh <- err; return }
475+
// break
476+
// }
477+
// } else {
478+
// runtime.EventsEmit(a.ctx, "currentStatus", fmt.Sprintf("等待检索课程 %s 结果...", courseID))
479+
// time.Sleep(time.Duration(speed) * time.Millisecond)
480+
// count += speed
481+
// }
482+
// }
483+
438484
// 点击 "确定"
439485
ele = iiframe.Locator("#btnSubmit")
440486
err = ele.Click()

frontend/src/components/Header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export function Header() {
4141
className='w-full h-full flex items-center justify-start text-sm gap-2 pl-3'
4242
>
4343
<span className='font-bold' data-tg-tour='测试'>小鸦抢课</span>
44-
<Tag id='version' className='m-0 border-rose-950 bg-white leading-none py-[0.15rem] px-[0.3rem]'>2.0.3</Tag>
44+
<Tag id='version' className='m-0 border-rose-950 bg-white leading-none py-[0.15rem] px-[0.3rem]'>2.1.0</Tag>
4545
<Tag id='status' className='m-0 border-rose-950 bg-white leading-none py-[0.15rem] px-[0.3rem]'>{systemStatus}</Tag>
4646
</p>
4747
<button

0 commit comments

Comments
 (0)