GO 定时执行链接
2022-01-12 10:33 天心PHP 阅读(59) 评论(0) 编辑 收藏 举报package main import ( "fmt" "io/ioutil" "net/http" "os" "strconv" "time" ) func main() { var pass string fmt.Println("请输入运行密码:") fmt.Scanln(&pass) if pass!="xsh123456" { fmt.Println("密码不对") os.Exit(0) } fmt.Println("请输入文件开始标题数和结束标题数——格式:x y") var x,y int fmt.Scanln(&x,&y) fmt.Printf("x的值:%d,y的值:%d\n",x,y) for i := x; i <= y; i++ { getUrl(i); time.Sleep(time.Duration(150)*time.Second) } } func getUrl(i int){ url := "/services/yunyi/yunyiproduct/importamazonadjust/line/"+strconv.Itoa(i) req, _ := http.NewRequest("GET", url, nil) res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := ioutil.ReadAll(res.Body) fmt.Println(string(body)) }
package main import ( "fmt" "io/ioutil" "net/http" "time" ) func main() { for { getUrl() time.Sleep(time.Duration(2) * time.Second) } } func getUrl() { url := "http://xxxxxx.xxxxxxx.com/services/amazon/amazonalllisting/getbrandgroup?id=1050&type=1" req, _ := http.NewRequest("GET", url, nil) res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := ioutil.ReadAll(res.Body) fmt.Println(string(body)) }