示例#1
0
func main() {
	x, err := utils.TomlReader("../config/auto_sign/auto_sign.conf")
	if err != nil {
		panic(err)
	}
	xpath := "/html/body/div[@id='Wrapper']/div[@class='content']/div[@id='Main']/div[@class='box'][1]/div[@class='cell']/form/table/tr[3]/td[2]/input[1]"
	randrom_token, err := GetRandom_token(x, xpath)
	if err != nil {
		panic(err)
	}

	postParam := map[string]interface{}{
		"u":    "windows98",
		"p":    "123456789",
		"once": randrom_token,
		"next": "/",
	}

	resp, err := Login(x, postParam)
	pp := ppDownloader.New(x.Header)
	x.Header.Cookie = resp.Response.Header["Set-Cookie"][0]
	resp, err = pp.Get("http://v2ex.com/mission/daily")

	// fmt.Println("url", x.Header.Host)
	// fmt.Println("httpCode:", resp.Response.StatusCode)
	fmt.Println("ret:", string(resp.Body))
}
示例#2
0
func ppDown() {
	ret, err := ppDownloader.New().Download("http://www.douban.com")
	if err != nil {
		panic(err)
	}

	fmt.Println("ret:", ret.Body)
}
示例#3
0
func Login(x *utils.Conf, postParam map[string]interface{}) (resp *ppDownloader.Downloader, err error) {
	pp := ppDownloader.New(x.Header)
	resp, err = pp.Post(x.Header.Host, postParam)
	if err != nil {
		return
	}
	return
}
示例#4
0
func GetRandom_token(x *utils.Conf, xpath string) (randrom_token string, err error) {
	pp := ppDownloader.New(x.Header)
	resp, err := pp.Get(x.Header.Host)
	if err != nil {
		return
	}
	result := ppDownloader.GetData(resp.Body, xpath)
	randrom_token = result["random_token"]
	if randrom_token == "" {
		err := errors.New("token失败")
		return "", err
	}
	return
}