forked from blueszeng/scu
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscu.go
38 lines (30 loc) · 792 Bytes
/
scu.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 scu
import (
"errors"
"regexp"
"github.com/gocolly/colly"
)
// NewCollector 新建一个采集器
func NewCollector(studentID, password string) (*colly.Collector, error) {
c := colly.NewCollector()
var logErr error
c.OnHTML("script", func(e *colly.HTMLElement) {
r, _ := regexp.Compile("错误")
if r.MatchString(e.Text) {
logErr = errors.New("[Error] 用户不存在或密码错误")
}
})
err := c.Post("http://my.scu.edu.cn/userPasswordValidate.portal", map[string]string{
"Login.Token1": studentID,
"Login.Token2": password,
"goto": "http://my.scu.edu.cn/loginSuccess.portal",
"gotoOnFail": "http://my.scu.edu.cn/loginFailure.portal",
})
if err != nil {
return nil, err
}
if logErr != nil {
return nil, logErr
}
return c, nil
}