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


Golang Node.Search方法代碼示例

本文整理匯總了Golang中github.com/moovweb/gokogiri/xml.Node.Search方法的典型用法代碼示例。如果您正苦於以下問題:Golang Node.Search方法的具體用法?Golang Node.Search怎麽用?Golang Node.Search使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/moovweb/gokogiri/xml.Node的用法示例。


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

示例1: trNodeToSchedule

func trNodeToSchedule(scheduleNode xml.Node) (item ScheduleItem, err error) {

	results, err := scheduleNode.Search("./td/text()")

	if err != nil {
		return ScheduleItem{}, err
	}

	item = ScheduleItem{
		TrainNumber:     strings.TrimSpace(results[1].String()),
		Misc:            strings.TrimSpace(results[2].String()),
		Class:           strings.TrimSpace(results[3].String()),
		Relation:        strings.TrimSpace(results[4].String()),
		StartingStation: strings.TrimSpace(results[5].String()),
		CurrentStation:  strings.TrimSpace(results[6].String()),
		ArrivingTime:    strings.TrimSpace(results[7].String()),
		DepartingTime:   strings.TrimSpace(results[8].String()),
		Ls:              strings.TrimSpace(results[9].String()),
	}

	if len(results) > 10 {
		item.Status = strings.TrimSpace(results[10].String())
	}

	stationParts := strings.FieldsFunc(item.Relation, func(r rune) bool {
		return r == '-'
	})

	item.EndStation = stationParts[1] // [ANGKE BOGOR] BOGOR is end station

	return
}
開發者ID:novan,項目名稱:go-kcj,代碼行數:32,代碼來源:helpers.go

示例2: Link

func Link(performance xml.Node) string {
	anchor, err := performance.Search(".//a")
	if err != nil {
		fmt.Println(err)
	}
	return "http://www.bso.org" + anchor[0].Attr("href")
}
開發者ID:shterrett,項目名稱:UpcomingConcerts,代碼行數:7,代碼來源:next_bso.go

示例3: getContent

func getContent(node gxtml.Node, cssQuery string) string {
	result, err := node.Search(toXpath(cssQuery))
	if err != nil {
		panic(fmt.Errorf("Failed to find %v node", cssQuery))
	}
	return result[0].Content()
}
開發者ID:jalkoby,項目名稱:easy_tracker,代碼行數:7,代碼來源:utils.go

示例4: parseSource

func parseSource(m xml.Node) string {
	res, _ := m.Search("source")

	if len(res) > 0 {
		return res[0].Content()
	}

	return ""
}
開發者ID:reapub,項目名稱:parser,代碼行數:9,代碼來源:oebpspackage.go

示例5: parseRights

func parseRights(m xml.Node) string {
	res, _ := m.Search("rights")

	if len(res) > 0 {
		return res[0].Content()
	}

	return ""
}
開發者ID:reapub,項目名稱:parser,代碼行數:9,代碼來源:oebpspackage.go

示例6: parsePublisher

func parsePublisher(m xml.Node) string {
	publisher := ""

	res, _ := m.Search("publisher")
	if len(res) > 0 {
		publisher = res[0].Content()
	}

	return publisher
}
開發者ID:reapub,項目名稱:parser,代碼行數:10,代碼來源:oebpspackage.go

示例7: parseLanguages

func parseLanguages(m xml.Node) []string {
	languages := []string{}

	res, _ := m.Search("language")
	for _, n := range res {
		languages = append(languages, n.Content())
	}

	return languages
}
開發者ID:reapub,項目名稱:parser,代碼行數:10,代碼來源:oebpspackage.go

示例8: parseTitles

func parseTitles(m xml.Node) []string {
	titles := []string{}

	res, _ := m.Search("title")
	for _, n := range res {
		titles = append(titles, n.Content())
	}

	return titles
}
開發者ID:reapub,項目名稱:parser,代碼行數:10,代碼來源:oebpspackage.go

示例9: parseSubjects

func parseSubjects(m xml.Node) []string {
	subjects := []string{}

	res, _ := m.Search("subject")
	for _, n := range res {
		subjects = append(subjects, n.Content())
	}

	return subjects
}
開發者ID:reapub,項目名稱:parser,代碼行數:10,代碼來源:oebpspackage.go

示例10: parseDescription

func parseDescription(m xml.Node) string {
	description := ""

	res, _ := m.Search("description")
	if len(res) > 0 {
		description = res[0].Content()
	}

	return description
}
開發者ID:reapub,項目名稱:parser,代碼行數:10,代碼來源:oebpspackage.go

示例11: parseIdentifiers

func parseIdentifiers(m xml.Node) []*Identifier {
	identifiers := []*Identifier{}

	res, _ := m.Search("identifier")
	for _, n := range res {
		identifier := Identifier{Identifier: n.Content(), Scheme: n.Attr("scheme")}
		identifiers = append(identifiers, &identifier)
	}

	return identifiers
}
開發者ID:reapub,項目名稱:parser,代碼行數:11,代碼來源:oebpspackage.go

示例12: Pieces

func Pieces(details xml.Node) string {
	pieces, _ := details.Search(".//div[@class='program-media-collapse']/h3")
	var piecesString string
	piecesString = "<ul class=\"works\">"
	for _, piece := range pieces {
		piecesString += "<li>"
		piecesString += piece.Content()
		piecesString += "</li>"
	}
	piecesString += "</ul>"
	return piecesString
}
開發者ID:shterrett,項目名稱:UpcomingConcerts,代碼行數:12,代碼來源:next_bso.go

示例13: linkDensity

func linkDensity(node xml.Node) float64 {
	links, err := node.Search("a")
	if err != nil {
		return 0.0
	}

	llength := 0.0
	for _, link := range links {
		llength += float64(len(link.Content()))
	}
	tlength := float64(len(node.Content()))
	return llength / tlength
}
開發者ID:oxmcvusd,項目名稱:readability-1,代碼行數:13,代碼來源:util.go

示例14: processNode

func processNode(node xml.Node, row string) {
	row = row + node.Attr("TEXT") + "|"
	kids, err := node.Search("node")
	if err != nil {
		log.Println("Error searching for node:", err)
		return
	}
	if len(kids) > 0 { // has children, not a leaf node
		for i := range kids {
			processNode(kids[i], row)
		}
	} else {
		fmt.Println(row) // print leaf node
	}
}
開發者ID:kkeuning,項目名稱:mm2psv,代碼行數:15,代碼來源:mm2psv.go

示例15: parseLeagues

/*
  Not working because:
  http://www.sc2ratings.com/players.php?realname=Yang,%20Hee-Soo
  is parsed as:
  http://www.sc2ratings.com/players.php?realname=Yang, Hee-Soo
*/
func parseLeagues(player xml.Node) []string {
	out := []string{}
	partialUrl, err := player.Search(".//a/@href")
	errorHandler(err)
	if len(partialUrl) == 1 {
		playerPageUrl := "http://www.sc2ratings.com/" + partialUrl[0].String()
		playerPageSource := retrievePageSource(playerPageUrl)

		playerPage, err := gokogiri.ParseHtml(playerPageSource)
		errorHandler(err)
		defer playerPage.Free()
		fmt.Println(playerPage)
	}
	return out
}
開發者ID:Nerazim,項目名稱:mule,代碼行數:21,代碼來源:player_scraper.go


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