Ejemplo n.º 1
0
func ScrapeMidUrl(mid_body io.ReadCloser) string {
	slug_tokens := html.NewTokenizer(mid_body)
	for {
		if slug_tokens.Next() == html.ErrorToken {
			// Returning io.EOF indicates success.
			return ""
		}
		tok := slug_tokens.Token()
		if tok.DataAtom == atom.Embed {
			file_url, err := webutils.GetAttr("src", tok.Attr)
			if err == nil && file_url != "" {
				return file_url
			}
		}
	}
	return ""
}
Ejemplo n.º 2
0
func ScrapeSlugs(songs_body io.ReadCloser) []string {
	var slugs []string

	z := html.NewTokenizer(songs_body)

	for {
		if z.Next() == html.ErrorToken {
			// Returning io.EOF indicates success.
			break
		}
		tok := z.Token()
		if tok.DataAtom == atom.Option {
			slug, err := webutils.GetAttr("value", tok.Attr)
			// Happens when there was no attr found
			if err == nil && slug != "" {
				slugs = append(slugs, slug)
			}
		}
	}
	return slugs
}
Ejemplo n.º 3
0
func ScrapeTopLink(search_body io.ReadCloser) string {
	log.Println("Scraping for top link")
	z := html.NewTokenizer(search_body)
	td_started := false
	for {
		if z.Next() == html.ErrorToken {
			// Returning io.EOF indicates success.
			break
		}
		tok := z.Token()
		if tok.DataAtom == atom.Td && tok.Type == html.StartTagToken {
			td_started = true
		} else if tok.DataAtom == atom.A && tok.Type == html.StartTagToken {
			if td_started {
				href, _ := webutils.GetAttr("href", tok.Attr)
				return href
			}
		}
	}
	return ""
}