Beispiel #1
0
func main() {
	u := "http://techcrunch.com/2015/09/09/ipad-pro-coming-in-november-pricing-starts-at-799/"

	resp, err := http.Get(u)

	if err != nil {
		panic(err)
	}

	defer resp.Body.Close()

	info := htmlinfo.NewHTMLInfo()

	ct := resp.Header.Get("Content-Type")

	// if url and contentType are not provided it's fine too, just then we wont be able to fetch (and generate) oembed information
	err = info.Parse(resp.Body, &u, &ct)

	if err != nil {
		panic(err)
	}

	fmt.Printf("Info:\n%s\n", info)

	fmt.Printf("Oembed information: %s\n", info.GenerateOembedFor(u))
}
Beispiel #2
0
func main() {
	u := "http://techcrunch.com/2010/11/02/365-days-10-million-3-rounds-2-companies-all-with-5-magic-slides/"

	resp, err := http.Get(u)

	if err != nil {
		panic(err)
	}

	defer resp.Body.Close()

	info := htmlinfo.NewHTMLInfo()
	info.AllowOembedFetching = true

	ct := resp.Header.Get("Content-Type")

	// if url and contentType are not provided it's fine too, just then we wont be able to fetch (and generate) oembed information
	err = info.Parse(resp.Body, &u, &ct)

	if err != nil {
		panic(err)
	}

	fmt.Printf("Info:\n%s\n", info)

	fmt.Printf("Oembed information: %s\n", info.GenerateOembedFor(u))
}
Beispiel #3
0
// FetchOembedFromHTML returns information extracted from html page
func (p *Parser) FetchOembedFromHTML(pageURL string, data []byte, contentType string) *oembed.Info {
	buf := bytes.NewReader(data)
	info := htmlinfo.NewHTMLInfo()
	info.Client = p.client
	info.AcceptLanguage = p.AcceptLanguage
	info.AllowOembedFetching = true

	if info.Parse(buf, &pageURL, &contentType) != nil {
		return nil
	}

	return info.GenerateOembedFor(pageURL)
}