package main import ( "fmt" "github.com/tebeka/selenium" "io/ioutil" "os" "ouch/student" "sync" ) func handleCount(accounts [][]string) { var wg sync.WaitGroup serviceArray := []*selenium.Service{} wds := []selenium.WebDriver{} for _, v := range accounts { fmt.Printf("账号:%v\n", v) //err := student.StartOneStudent("2051101453478", "Ouchn19991209", "李丰") wg.Add(1) go func(name string, pass string, real string) { // 开始执行 service, wd, err := student.StartOneStudent(name, pass, real) if service != nil { serviceArray = append(serviceArray, service) } if wd != nil { wds = append(wds, wd) } if err != nil { fmt.Printf("%s %v \n", v[2], err) } wg.Done() }(v[0], v[1], v[2]) //time.Sleep(20*time.Second) } wg.Wait() for _, v := range wds { v.Quit() } for _, v := range serviceArray { v.Stop() } } func main() { // 取账号 accounts, _ := student.GetAcounts("account.txt") fmt.Printf("accounts:%v\n", len(accounts)) for _, v := range accounts { if len(v) != 3 { fmt.Printf("账号不完整\n") return } } start := 0 end := 1 for { if end > len(accounts) { end = len(accounts) } if start >= end { break } // 处理账号 handleCount(accounts[start:end]) // 记录执行过的账号 str := fmt.Sprintf("start:%d,%s,%s,%s end:%d,%s,%s,%s\r\n", start, accounts[start][0], accounts[start][1], accounts[start][2], end, accounts[end-1][0], accounts[end-1][1], accounts[end-1][2],) os.Remove("record.txt") ioutil.WriteFile("record.txt", []byte(str), 0666) //fmt.Printf("finish one\n") //time.Sleep(1000*time.Second) start = end end = end + 1 } fmt.Printf("over\n") //time.Sleep(100*time.Second) }