示例#1
0
//没有Forum
func OldGetAdvSearchResultList(kw, un string, rn,
	pn int) ([]AdvSearchResult, error) {
	resp, err := GetAdvSearchResultPage(kw, un, rn, pn)

	if err != nil {
		return nil, err
	}
	results := advreg.FindAllStringSubmatch(misc.FromGBK(resp), -1)
	if len(results) == 0 {
		return nil, nil
	}

	asrs := make([]AdvSearchResult, len(results))

	for i, result := range results {
		asr := &asrs[i]
		asr.Tid, _ = strconv.ParseUint(result[1], 10, 64)
		asr.Pid, _ = strconv.ParseUint(result[2], 10, 64)
		asr.IsReply = result[3] == `回复:`
		asr.Title = result[4]
		asr.Content = result[5]

		var y, m, d, hour, min int
		fmt.Sscanf(result[6], "%d-%d-%d %d:%d", &y, &m, &d, &hour, &min)
		asr.PostTime = time.Date(y, time.Month(m), d, hour, min, 0, 0, time.Local)

		asr.Author.Name = un

	}

	return asrs, nil

}
示例#2
0
func ParseAdvSearchDocument(doc *goquery.Document) []AdvSearchResult {
	posts := doc.Find(`div.s_post_list`).Eq(0).Find(`div.s_post`)
	results := make([]AdvSearchResult, posts.Length())
	posts.Each(func(index int, post *goquery.Selection) {
		result := &results[index]
		bluelink := post.Find(`a.bluelink`)
		title := bluelink.Text()
		oldLen := len(title)
		result.Title = strings.TrimPrefix(misc.FromGBK(title), `回复:`)
		result.IsReply = oldLen != len(result.Title)
		link, _ := bluelink.Attr(`href`)

		ids := idreg.FindStringSubmatch(link)

		if len(ids) != 3 {
			logs.Error("高级搜索结果链接异常,跳过:", link, ".")
			goto CONTINUE
		}
		{
			result.Tid, _ = strconv.ParseUint(ids[1], 10, 64)
			result.Pid, _ = strconv.ParseUint(ids[2], 10, 64)

			result.Content = misc.FromGBK(post.Find(`div.p_content`).Text())

			date := misc.FromGBK(post.Find(`font.p_date`).Text())
			var y, m, d, hour, min int
			fmt.Sscanf(date, "%d-%d-%d %d:%d", &y, &m, &d, &hour, &min)
			result.PostTime = time.Date(y, time.Month(m), d, hour, min, 0, 0, time.Local)

			x := post.Find(`font.p_violet`)
			result.Forum = misc.FromGBK(x.First().Text())
			result.Author.Name = misc.FromGBK(x.Next().Text())

		}

	CONTINUE:
	})

	return results
}