本文整理匯總了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
}
示例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")
}
示例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()
}
示例4: parseSource
func parseSource(m xml.Node) string {
res, _ := m.Search("source")
if len(res) > 0 {
return res[0].Content()
}
return ""
}
示例5: parseRights
func parseRights(m xml.Node) string {
res, _ := m.Search("rights")
if len(res) > 0 {
return res[0].Content()
}
return ""
}
示例6: parsePublisher
func parsePublisher(m xml.Node) string {
publisher := ""
res, _ := m.Search("publisher")
if len(res) > 0 {
publisher = res[0].Content()
}
return publisher
}
示例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
}
示例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
}
示例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
}
示例10: parseDescription
func parseDescription(m xml.Node) string {
description := ""
res, _ := m.Search("description")
if len(res) > 0 {
description = res[0].Content()
}
return description
}
示例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
}
示例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
}
示例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
}
示例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
}
}
示例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
}