本文整理匯總了Golang中github.com/moovweb/gokogiri/xml.Node類的典型用法代碼示例。如果您正苦於以下問題:Golang Node類的具體用法?Golang Node怎麽用?Golang Node使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Node類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GetAsset
func (s *Scenario) GetAsset(w *Worker, base *url.URL, node xml.Node, attr string) error {
path, err := url.Parse(node.Attr(attr))
if err != nil {
return w.Fail(nil, err)
}
requestURI := base.ResolveReference(path)
req, res, err := w.SimpleGet(requestURI.String())
if err != nil {
return w.Fail(req, err)
}
if res.StatusCode != 200 {
return w.Fail(res.Request, fmt.Errorf("Response code should be %d, got %d", 200, res.StatusCode))
}
md5sum := calcMD5(res.Body)
defer res.Body.Close()
if expectedMD5, ok := s.ExpectedAssets[requestURI.RequestURI()]; ok {
if md5sum == expectedMD5 {
w.Success(StaticFileScore)
} else {
return w.Fail(res.Request, fmt.Errorf("Expected MD5 checksum is miss match %s, got %s", expectedMD5, md5sum))
}
}
return nil
}
示例2: 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
}
示例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: 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")
}
示例5: extend
func extend(doc *xml.ElementNode, node xml.Node) {
dup := node.Duplicate(1).(*xml.ElementNode)
doc.AddChild(dup)
if strings.ToLower(dup.Name()) != "p" || strings.ToLower(dup.Name()) != "div" {
dup.SetName("div")
}
}
示例6: MapRegex
func (s *scrape) MapRegex(node xml.Node) (map[string]string, error) {
if node.IsValid() == false {
return nil, errors.New("Invalid node")
}
m := make(map[string]string, 1)
inner := node.String()
for k, v := range ScrapeRegex {
// remove new line chars
reg, _ := regexp.CompilePOSIX("\r\n|\r|\n")
inner = reg.ReplaceAllString(inner, "")
// get the real data
reg, _ = regexp.CompilePOSIX(v[0])
scraped := reg.FindString(inner)
scraped = reg.ReplaceAllString(scraped, "$1")
if scraped != "" {
m[k] = scraped
}
}
// Skip empty and unwanted
if len(m) > 0 {
if m[ScrapeMeta[IGNOREEMPTY]] != "" {
return m, nil
}
return nil, nil
}
return nil, nil
}
示例7: parseSource
func parseSource(m xml.Node) string {
res, _ := m.Search("source")
if len(res) > 0 {
return res[0].Content()
}
return ""
}
示例8: walk
// Walks through the documents elements and populates the buffer.
func (self *Formatter) walk(node xml.Node) {
for c := node.FirstChild(); c != nil; c = c.NextSibling() {
self.walk(c)
}
if node.NodeType() == xml.XML_ELEMENT_NODE {
self.handleNode(node)
}
}
示例9: parseRights
func parseRights(m xml.Node) string {
res, _ := m.Search("rights")
if len(res) > 0 {
return res[0].Content()
}
return ""
}
示例10: writeCodeBlock
// Writes code blocks to the buffer.
func (self *Formatter) writeCodeBlock(node xml.Node) {
block := []byte(strings.Trim(node.Content(), "\n\r\v"))
node.SetContent("")
if len(block) == 0 {
return
}
self.buf.Write(block)
self.buf.Write([]byte{'\n', '\n'})
}
示例11: walkElements
func (this *Document) walkElements(node xml.Node, f func(xml.Node) error) error {
f(node)
for child := node.FirstChild(); child != nil; child = child.NextSibling() {
err := this.walkElements(child, f)
if err != nil {
return err
}
}
return nil
}
示例12: parseSubjects
func parseSubjects(m xml.Node) []string {
subjects := []string{}
res, _ := m.Search("subject")
for _, n := range res {
subjects = append(subjects, n.Content())
}
return subjects
}
示例13: parseDescription
func parseDescription(m xml.Node) string {
description := ""
res, _ := m.Search("description")
if len(res) > 0 {
description = res[0].Content()
}
return description
}
示例14: parsePublisher
func parsePublisher(m xml.Node) string {
publisher := ""
res, _ := m.Search("publisher")
if len(res) > 0 {
publisher = res[0].Content()
}
return publisher
}
示例15: parseTitles
func parseTitles(m xml.Node) []string {
titles := []string{}
res, _ := m.Search("title")
for _, n := range res {
titles = append(titles, n.Content())
}
return titles
}