示例#1
0
func login(session *http.Session, user, pass String) error {
	resp, err := session.Post(
		"http://bbs.saraba1st.com/2b/member.php",
		Dict{
			"params": Dict{
				"mod":         "logging",
				"action":      "login",
				"loginsubmit": "yes",
				"infloat":     "yes",
				"lssubmit":    "yes",
				"inajax":      "1",
			},
			"body": Dict{
				"fastloginfield": "username",
				"quickforward":   "yes",
				"handlekey":      "ls",
				"username":       user,
				"password":       pass,
			},
			"encoding": strings.CP_UTF8,
		},
	)

	if err != nil {
		return err
	}

	if resp.StatusCode != http.StatusOK {
		return Errorf("login status: %s", http.StatusText(resp.StatusCode))
	}

	return nil
}
示例#2
0
文件: s1.go 项目: pmeido/Arianrhod
func openThread(session *http.Session, user String) {
	doc := openPage(session, FORUM_URL)

	threads := []*goquery.Selection{}

	doc.Find("tbody").Each(func(i int, s *goquery.Selection) {
		id_, exist := s.Attr("id")
		id := String(id_)
		if exist && id.StartsWith("normalthread_") {
			threads = append(threads, s)
		}
	})

	if len(threads) == 0 {
		Raise("empty thread")
	}

	index := random.IntRange(0, len(threads))
	t := threads[index].Find("a.s.xst")
	href, ok := t.Attr("href")

	if ok == false {
		Raise("can't find thread addr")
	}

	credit := String(doc.Find("#extcreditmenu").Text())
	console.SetTitle(credit.Split(":", 1)[1])

	Printf("[%s][%s] %s @ %s\n", time.Now().Format("2006-01-02 15:04:05"), user, credit, t.Text())

	session.Get(BASE_URL + href)
}
示例#3
0
文件: s1.go 项目: pmeido/Arianrhod
func openPage(session *http.Session, url String) (doc *goquery.Document) {
	resp := session.Get(url)

	doc, err := goquery.NewDocumentFromReader(strings.Decode(resp.Content, resp.Encoding).NewReader())
	RaiseIf(err)

	return
}
示例#4
0
func openPage(session *http.Session, url String) (doc *goquery.Document, err error) {
	resp, err := session.Get(url)

	if err != nil {
		return nil, err
	}

	doc, err = goquery.NewDocumentFromReader(strings.Decode(resp.Content, resp.Encoding).NewReader())
	return
}
示例#5
0
文件: s1.go 项目: pmeido/Arianrhod
func logout(session *http.Session) {
	doc := openPage(session, FORUM_URL)

	doc.Find("a").Each(func(i int, s *goquery.Selection) {
		href_, exist := s.Attr("href")
		href := String(href_)
		if exist && href.Contains("action=logout") {
			session.Get(BASE_URL + href)
		}
	})
}
示例#6
0
func logout(session *http.Session) error {
	doc, err := openPage(session, FORUM_URL)
	if err != nil {
		return err
	}

	doc.Find("a").Each(func(i int, s *goquery.Selection) {
		href_, exist := s.Attr("href")
		href := String(href_)
		if exist && href.Contains("action=logout") {
			session.Get(BASE_URL + href)
		}
	})

	return nil

	// logout = logout and page.find(lambda e : e.get('href') and 'action=logout' in e['href'])
	// if logout:
	//     yield from http.request('get', BASE_URL + logout['href'])
}