|
本帖最后由 waini1110 于 2018-8-17 09:56 编辑
其实就是因为论坛上了https,所以签到什么的都有点问题了。
交叉编译: GOOS=linux GOARCH=amd64 go build
在编译好的二进制里面放一个json,用于储存你的账号密码。
[ol]{ "username": "username", "password": "password"}[/ol]复制代码
[ol]package mainimport ( "crypto/tls" "encoding/json" "fmt" "io/ioutil" "math/rand" "net/http" "net/http/cookiejar" "os" "regexp" "strconv" "strings" "time" "github.com/PuerkitoBio/goquery")var ( LoginUrl = "https://www.hs2v.com/member.php?mod=logging&action=login&loginsubmit=yes&frommessage&loginhash=LL970&inajax=1")type User struct { Username string `json:username` Password string `json:password`}type Client struct { Client *http.Client Integral int Ch chan string User}func (c *Client) Login() { jar, err := cookiejar.New(nil) if err != nil { fmt.Printf("cookie error:%s", err) } c.Client.Jar = jar req, err := http.NewRequest("POST", LoginUrl, strings.NewReader("username="+c.User.Username+"&password="+c.User.Password)) if err != nil { fmt.Printf("httpRequest error:\r\n", err) os.Exit(1) } req.Header.Set("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8") req.Header.Set("Accept-Language", "zh-CN,zh;q=0.9") req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.79 Safari/537.36") req.Header.Set("Host", "www.hs2v.com") req.Header.Set("Content-Type", "application/x-www-form-urlencoded") resp, _ := c.Client.Do(req) defer resp.Body.Close() doc, err := goquery.NewDocumentFromResponse(resp) if err != nil { fmt.Printf("Parsing HTML error%s:\r\n", err) os.Exit(1) } html, _ := doc.Html() if ok := strings.Contains(html, "登录失败"); ok { fmt.Printf("Login failure\r\n") os.Exit(1) } c.Visit()}func (c *Client) Visit() { r := rand.New(rand.NewSource(time.Now().UnixNano())) for x := 0; x c.Integral { c.Integral = a } fmt.Println(c.Integral) } resp, err := c.Client.Get("https://www.hs2v.com/forum.php") defer resp.Body.Close() if err != nil { fmt.Printf("visit error:%s\r\n", err) os.Exit(1) } doc, err := goquery.NewDocumentFromResponse(resp) if err != nil { fmt.Printf("Parsing HTML error:%s\r\n", err) os.Exit(1) } fmt.Printf("your Integral is: %s\r\n", doc.Find("#extcreditmenu").Text())}func main() { var user User data, err := ioutil.ReadFile("user.json") if err != nil { fmt.Printf("read file faild:%s", err) } json.Unmarshal(data, &user) client := Client{ Client: &http.Client{ Transport: &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, DisableCompression: true, }, }, Integral: 0, Ch: make(chan string, 1), User: user, } client.Login() fmt.Println("Closed after 5 seconds") time.Sleep(5 * time.Second)}[/ol]复制代码 |
|