自动领豆golang版

前端之家收集整理的这篇文章主要介绍了自动领豆golang版前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
packagemain
//51cto自动领豆
import(
"github.com/crufter/goquery"
"fmt"
"math/rand"
"net/http/cookiejar"
"net/http"
"net/url"
"io/IoUtil"
"strconv"
)
//用户名和密码
const(
NAME="username"
PWD="password"
)
funcmain(){
//设置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(WindowsNT6.1;WOW64;rv:14.0)Gecko/20100101Firefox/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("http://blog.51cto.com/appApi/sign/sign")

}
原文链接:https://www.f2er.com/go/187916.html

猜你在找的Go相关文章