當前位置: 首頁>>代碼示例>>Golang>>正文


Golang h5.Tree類代碼示例

本文整理匯總了Golang中code/google/com/p/go-html-transform/h5.Tree的典型用法代碼示例。如果您正苦於以下問題:Golang Tree類的具體用法?Golang Tree怎麽用?Golang Tree使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Tree類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: treeFind

func treeFind(t h5.Tree, e, key string, f func(h5.Tree, html.Attribute)) {
	t.Walk(func(n *html.Node) {
		if a := getAttr(n, key); n.Data == e && a != nil {
			f(h5.NewTree(n), *a)
		}
	})

}
開發者ID:ronbu,項目名稱:websync,代碼行數:8,代碼來源:zdf.go

示例2: getTitleNode

func getTitleNode(document *h5.Tree) (titleNode string, err error) {
	var chain *selector.Chain

	if chain, err = selector.Selector("title"); err != nil {
		return
	}

	if matches := chain.Find(document.Top()); len(matches) > 0 {
		match := matches[0:1]
		titleNode = h5.RenderNodesToString(match)
	}

	return
}
開發者ID:happypancake,項目名稱:go-pjax,代碼行數:14,代碼來源:PjaxFilter.go

示例3: ExtractReader

// ExtractReader - Acts like Extract but first parses html body from reader.
func (m SelectorsMap) ExtractReader(buffer io.Reader) (res interface{}, err error) {
	// If no buffer return error
	if buffer == nil {
		err = ErrNoBody
		return
	}

	// Parse body
	var node *h5.Tree
	node, err = h5.New(buffer)
	if err != nil {
		return
	}

	// Extract from top node
	res = m.Extract(node.Top())
	return
}
開發者ID:crackcomm,項目名稱:go-core,代碼行數:19,代碼來源:selectors.go

示例4: rewriteBody

func rewriteBody(containerSelector string, dest io.Writer, body string) (err error) {
	if containerSelector == "" {
		dest.Write([]byte(body))
		return
	}

	var chain *selector.Chain
	var document *h5.Tree

	if document, err = h5.NewFromString(body); err != nil {
		err = fmt.Errorf("invalid html document: %v", err)
		return
	}

	var titleNode string
	if titleNode, err = getTitleNode(document); err != nil {
		return
	}

	if chain, err = selector.Selector(containerSelector); err != nil {
		err = fmt.Errorf("invalid css: %v", containerSelector)
		return
	}

	if matches := chain.Find(document.Top()); len(matches) > 0 {
		match := matches[0:1] // Take only the first match
		newBody := h5.RenderNodesToString(h5.Children(match[0]))

		fmt.Printf("data: %v", h5.Data(match[0]))

		dest.Write([]byte(titleNode))
		dest.Write([]byte(newBody))
		return
	}

	err = fmt.Errorf("container not found")
	return
}
開發者ID:happypancake,項目名稱:go-pjax,代碼行數:38,代碼來源:PjaxFilter.go

示例5: New

// Constructor for a Transformer. It makes a copy of the document
// and transforms that instead of the original.
func New(t *h5.Tree) *Transformer {
	clone := t.Clone()
	return newTransformer(&clone)
}
開發者ID:jShi-git,項目名稱:goquery_sample,代碼行數:6,代碼來源:transform.go


注:本文中的code/google/com/p/go-html-transform/h5.Tree類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。