Exemplo n.º 1
0
func main() {
	doc, err := goquery.NewDocumentFromReader(strings.NewReader(allNodes))
	if err != nil {
		t.Fatal(err)
	}

	in := []string{"p", "h1", "div"}
	var out []string
	doc.Find(strings.Join(in, ", ")).Each(func(i int, s *Selection) {
		got := goquery.NodeName(s)
		out = append(out, got)
	})
	sort.Strings(in)
	sort.Strings(out)
	if !reflect.DeepEqual(in, out) {
		t.Errorf("want %v, got %v", in, out)
	}
}
Exemplo n.º 2
0
func get_sesiones(selection_strong *goquery.Selection) (hubo bool) {
	div_selection := selection_strong.Parent()
	selection := div_selection.Next()
	var table_selction *goquery.Selection
	hubo = false
	for {
		tipo := goquery.NodeName(selection)
		if tipo == "table" {
			hubo = true
			table_selction = selection
			break
		} else if tipo == "div" && len(selection.Find("strong").Nodes) != 0 {
			return
		} else if len(selection.Nodes) == 0 {
			return
		}
		selection = selection.Next()
	}
	tr_selection := table_selction.Find("tr")
	for idx_tr := 0; idx_tr < len(tr_selection.Nodes); idx_tr++ {
		td_selection := tr_selection.Eq(idx_tr).Find("td")
		// puesto, nombre, dias, horas, salon
		if len(td_selection.Nodes) > 5 {
			fmt.Println(td_selection.Text())
			hubo = false
			return
		}
		for idx_td := 0; idx_td < len(td_selection.Nodes); idx_td++ {
			if strings.TrimSpace(td_selection.Eq(idx_td).Text()) == "" {
				hubo = false
				return
			}
		}
	}
	return
}