-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.go
38 lines (34 loc) · 899 Bytes
/
login.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"github.com/antchfx/htmlquery"
"github.com/gookit/color"
)
func (r *Tagger) Login() error {
color.Greenln("用户名: " + r.username)
color.Greenln("尝试登录 WordPress.org...")
captcha, err := r.GetRecaptcha()
if err != nil {
return err
}
resp, err := r.client.R().
SetFormData(map[string]string{
"log": r.username,
"pwd": r.password,
"rememberme": "forever",
"wp-submit": "Log In",
"redirect_to": "https://cn.wordpress.org/wp-admin/",
"_reCaptcha_v3_token": captcha,
}).Post("https://login.wordpress.org/wp-login.php")
if err != nil {
return err
}
doc, err := htmlquery.Parse(resp.Body)
if err != nil {
return err
}
errnode := htmlquery.FindOne(doc, `//*[@id="login_error"]/p`)
if errnode != nil {
color.Redf("%s\n", htmlquery.InnerText(errnode))
}
return nil
}