golang代码如下: package main import ( "fmt" "github.com/aWildProgrammer/goticker" "github.com/tidwall/gjson" "io/ioutil" "net/http" "os" "os/exec" "time" ) func isAppNotFinish() bool { url := "https://你的域名/api/uploadGoodsDetail?type=app" method := "GET" client := &http.Client{} req, err := http.NewRequest(method, url, nil) if err != nil { fmt.Println(err) return false } req.Header.Add("Cookie", "PHPSESSID=3075ec176a43543f3995ba0f0c0b797a") res, err := client.Do(req) if err != nil { fmt.Println(err) return false } defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Println(err) return false } jsonStr := string(body) product_id := gjson.Get(jsonStr, "data.product_id").String() if len(product_id) > 7 { return true } else { return false } } func main() { task := goticker.New(100, false) ch2 := make(chan bool, 0) ch02 := make(chan bool, 0) ch03 := make(chan bool, 0) ch04 := make(chan bool, 0) ch05 := make(chan bool, 0) ch06 := make(chan bool, 0) //每隔1800秒执行 //task1 := task.AddTaskCallBackFunc(taskone, 300, "proxy-h5循环采集") task1 := task.AddTaskCallBackFunc(taskone, 1, "proxy-h5循环采集") task2 := task.AddTaskCallBackChannel(ch2, 3000) task02 := task.AddCycleTaskCallBackChannel(ch02, "02:18:55") task03 := task.AddCycleTaskCallBackChannel(ch03, "03:18:55") task04 := task.AddCycleTaskCallBackChannel(ch04, "04:18:55") task05 := task.AddCycleTaskCallBackChannel(ch05, "05:18:55") task06 := task.AddCycleTaskCallBackChannel(ch06, "06:18:55") fmt.Println(task1, task2, task02, task03, task04, task05, task06) for { select { case <-ch2: fmt.Println("每间隔3000秒任务task2") rebootRouterNow() exeonlyH5() case <-ch02: fmt.Println("每天 02:18:55任务task02") rebootRouterNow() exeonlyH5() case <-ch03: fmt.Println("每天 03:18:55任务task03") rebootRouterNow() exeonlyH5() case <-ch04: fmt.Println("每天 04:18:55任务task04") rebootRouterNow() exeonlyH5() case <-ch05: fmt.Println("每天 05:18:55任务task05") rebootRouterNow() exeonlyH5() case <-ch06: fmt.Println("每天 06:18:55任务task06") rebootRouterNow() exeonlyH5() } } } func rebootRouterNow() { //先关闭全部浏览器 cmdLine2 := "taskkill /F /IM chrome.exe" cmd2 := exec.Command("cmd.exe", "/c", "start "+cmdLine2) err2 := cmd2.Run() fmt.Printf("%s, error:%v \n", cmdLine2, err2) cmdLine1 := "selenium_chrome/onlyH5Root.exe" if PathExists(cmdLine1) { fmt.Println(cmdLine1) cmd1 := exec.Command("cmd.exe", "/c", "start "+cmdLine1) err1 := cmd1.Run() fmt.Printf("%s, error:%v \n", cmdLine1, err1) time.Sleep(3 * time.Minute) } } func exeonlyH5() { pythonFile := "ProxyH5NoLimit" cmdLine1 := "fetch_log/douyinproxy.exe" fmt.Println(cmdLine1) cmd1 := exec.Command("cmd.exe", "/c", "start "+cmdLine1) err1 := cmd1.Run() fmt.Printf("%s, error:%v \n", cmdLine1, err1) if isAppNotFinish() { //app未采集完成就开启开个窗口进行采集 cmdLine := "python ./" + pythonFile + ".py" fmt.Println(cmdLine) cmd := exec.Command("cmd.exe", "/c", "start "+cmdLine) err := cmd.Run() fmt.Printf("%s, error:%v \n", cmdLine, err) time.Sleep(5 * time.Minute) cmdLine2 := "python ./" + pythonFile + ".py" fmt.Println(cmdLine2) cmd2 := exec.Command("cmd.exe", "/c", "start "+cmdLine2) err2 := cmd2.Run() fmt.Printf("%s, error:%v \n", cmdLine2, err2) time.Sleep(5 * time.Minute) cmdLine3 := "python ./" + pythonFile + ".py" fmt.Println(cmdLine3) cmd3 := exec.Command("cmd.exe", "/c", "start "+cmdLine3) err3 := cmd3.Run() fmt.Printf("%s, error:%v \n", cmdLine3, err3) time.Sleep(5 * time.Minute) } else { //app采集完成,就只打开一个页面进行采集 cmdLine := "python ./" + pythonFile + ".py" fmt.Println(cmdLine) cmd := exec.Command("cmd.exe", "/c", "start "+cmdLine) err := cmd.Run() fmt.Printf("%s, error:%v \n", cmdLine, err) time.Sleep(time.Duration(2) * time.Second) } } func taskone(args interface{}) { fmt.Println(args) fmt.Println("存在selenium_chrome/onlyH5Root.exe,就会采集前重启路由器" + time.Now().String()) } func test(args interface{}) { fmt.Println(args) } func PathExists(path string) bool { _, err := os.Stat(path) if err == nil { return true } if os.IsNotExist(err) { return false } return false }