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) }
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 }
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 }
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) } }) }
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']) }