package main //51cto自動領豆 import ( "github.com/crufter/goquery" "fmt" "math/rand" "net/http/cookiejar" "net/http" "net/url" "io/ioutil" "strconv" ) //用戶名和密碼 const ( NAME = "username" PWD = "password" ) func main() { //設置cookie cookieJar,_ := cookiejar.New(nil) client := &http.Client{ Jar:cookieJar, } //獲取CSRF隱藏字段 req , _ := http.NewRequest("GET","http://home.51cto.com/index",nil) req.Header.Set("User-Agent","'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1") req.Header.Set("Referer","http://home.51cto.com/index") req.Header.Set("Connection","[keep-alive]") res ,_ := client.Do(req) doc ,_ := goquery.Parse(res.Body) csrf := doc.Find("input").Val() //構造登錄認證數據 val := url.Values{} val.Set("LoginForm[username]",NAME) val.Set("LoginForm[password]",PWD) val.Set("_csrf",csrf) val.Set("LoginForm[rememberMe]","0") //登錄獲取cookie client.PostForm("http://home.51cto.com/index",val) //構造領豆數據 val_down := url.Values{} val_down.Set("do","getfreecredits") random_num := strconv.Itoa(rand.Float64()) val_down.Set("t",random_num) //領豆 res_my ,_ := client.PostForm("http://down.51cto.com/download.php",val_down) body1 ,_ := ioutil.ReadAll(res_my.Body) fmt.Println(string(body1)) //領取無憂幣 client.Get("https://blog.51cto.com/appApi/sign/sign") }