From 826d15876a3334a5b38d893a6b96e7597c8847ef Mon Sep 17 00:00:00 2001 From: eson Date: Tue, 4 Aug 2020 14:12:00 +0800 Subject: [PATCH] fix windows quit --- tasks/twitch/twitch_task1/task_twitch.go | 5 ++--- tasks/twitch/twitch_task2/task_twitch.go | 2 +- utils.go | 7 +++---- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/tasks/twitch/twitch_task1/task_twitch.go b/tasks/twitch/twitch_task1/task_twitch.go index 2b385ed..d98b28b 100644 --- a/tasks/twitch/twitch_task1/task_twitch.go +++ b/tasks/twitch/twitch_task1/task_twitch.go @@ -51,7 +51,6 @@ func (cl *ChannelLink) Execute() { var hrefs map[string]bool = make(map[string]bool) var delayerror = 5 - var samecount = 0 for i := 0; i <= 200; i++ { cards, err := wd.FindElements(selenium.ByXPATH, "//span/a[contains(@data-a-target,'card-') and @href]") if err != nil { @@ -59,7 +58,7 @@ func (cl *ChannelLink) Execute() { break } - if len(cards) == samecount { + if len(hrefs) == 0 { delayerror-- if delayerror <= 0 { break @@ -80,7 +79,7 @@ func (cl *ChannelLink) Execute() { } break } - samecount = len(cards) + if ps.IsClose() { break } diff --git a/tasks/twitch/twitch_task2/task_twitch.go b/tasks/twitch/twitch_task2/task_twitch.go index 52773de..95899c0 100644 --- a/tasks/twitch/twitch_task2/task_twitch.go +++ b/tasks/twitch/twitch_task2/task_twitch.go @@ -29,12 +29,12 @@ func (cl *UserList) Execute() { //article//a[@data-a-target='preview-card-title-link'] wd := intimate.GetChromeDriver(3030) + defer wd.Quit() ps := intimate.NewPerfectShutdown() counter := intimate.NewCounter() counter.SetMaxLimit(100) counter.SetMaxToDo(func(olist ...interface{}) error { owd := olist[0].(*selenium.WebDriver) - (*owd).Close() (*owd).Quit() *owd = intimate.GetChromeDriver(3030) return nil diff --git a/utils.go b/utils.go index ebee59b..53734ab 100644 --- a/utils.go +++ b/utils.go @@ -103,10 +103,9 @@ func GetChromeDriver(port int) selenium.WebDriver { panic(err) } runtime.SetFinalizer(wd, func(obj interface{}) { - - if err := obj.(selenium.WebDriver).Close(); err != nil { - log.Println(err) - } + // if err := obj.(selenium.WebDriver).Close(); err != nil { + // log.Println(err) + // } if err := obj.(selenium.WebDriver).Quit(); err != nil { log.Println(err) }