使用了beego框架用toolbox.NewTask定时去执行一个func. func代码如下
func Bocais() error { //fmt.Println(time.Now().Format("2006/1/2 15:04:05")) url := "https://www.7454cc.com/Lottery/Autocqssc" payload := strings.NewReader("------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"RequestVerificationToken\"\r\n\r\ns3G01KZ8H9YSlU_HwS-5AUVZHMotO8Hta0SzQ12BJIHl7GspdCu8L4CoCjvDk2wt_tgvEt7xGIbBtMjy0xJTomJ0hoe9JxHIbLSIavfMDn-WmxE_GCYrtZoBNfcZiQ7CU9agpxbxdg0zyBwTmM5xkK-1bvNgIibpslBBSL6FE41\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"class1\"\r\n\r\n1\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--") req, := http.NewRequest("POST", url, payload) req.Header.Add("content-type", "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW") req.Header.Add("Accept", "application/json") req.Header.Add("Cookie", "ASP.NET_SessionId=onab1ylbwmez1ld5j420r0n5; RequestVerificationToken=mKcx8gEZ7M66CZa6Uqm9VhQfuc79iQqqaZZ1FFIZwYYlFuLyvEqeA_a3Z145PxiCSIf73QOk-jsOtUir1gHnNjdTFAR-kxLZXWTy2MAJGhRYTfPUFuPYvgo0KRw61DjHZAMAqEvURVlXYxXgh4OJOg2") req.Header.Add("cache-control", "no-cache")
res, err := http.DefaultClient.Do(req)
defer res.Body.Close()
if err != nil {
fmt.Println("http请求失败")
return err
}
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println("body解析失败:" + string(body[:]))
return err
}
e := controllers.BocaiCache(body)
if e != nil {
fmt.Println(e)
}
return nil
}
BocaiCache方法如下
var i = 0 var number = ""
func BocaiCache(body []byte) error {
i++
fmt.Println(i)
exp := regexp.MustCompile("hm":\[(.+)\],
)
result1 := exp.FindAllSubmatch(body, -1)
str := string(result1[0][1])
if number != str {
fmt.Print("oldNumber:"+number+"->newNumber:"+str)
number = str
}
return nil
}
运行了大概一个半小时报错 panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x40 pc=0x827177]
goroutine 3869 [running]: main.Bocais(0x0, 0x0) C:/Users/Administrator/Desktop/go/src/bocai/main.go:37 +0x1d7 github.com/astaxie/beego/toolbox.(*Task).Run(0xc42011c180, 0xbf2580, 0x6e96bccddb4) C:/Users/Administrator/Desktop/go/src/github.com/astaxie/beego/toolbox/task.go:143 +0x32 created by github.com/astaxie/beego/toolbox.run C:/Users/Administrator/Desktop/go/src/github.com/astaxie/beego/toolbox/task.go:424 +0x1fd
截图如下
请大神解惑 不胜感激
有疑问加站长微信联系(非本文作者)
