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")
}
网页题目:自动领豆golang版
标题网址:
http://bzwzjz.com/article/gdhpoe.html