本文整理汇总了Golang中github.com/PuerkitoBio/goquery.Selection.AttrOr方法的典型用法代码示例。如果您正苦于以下问题:Golang Selection.AttrOr方法的具体用法?Golang Selection.AttrOr怎么用?Golang Selection.AttrOr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/PuerkitoBio/goquery.Selection
的用法示例。
在下文中一共展示了Selection.AttrOr方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: node
// node returns a string representation of the selection.
func node(i int, s *goquery.Selection) string {
switch node := s.Get(0); {
case node.Data == "h1":
return fmt.Sprintf(" \033[%dm# %s\033[0m\n\n", blue, text(s))
case node.Data == "h2":
return fmt.Sprintf(" \033[%dm## %s\033[0m\n\n", blue, text(s))
case node.Data == "h3":
return fmt.Sprintf(" \033[%dm### %s\033[0m\n\n", blue, text(s))
case node.Data == "p":
return fmt.Sprintf("\033[%dm%s\033[0m\n\n", none, indent(text(s), 1))
case node.Data == "pre" || s.HasClass("highlight"):
return fmt.Sprintf("\033[1m%s\033[0m\n\n", indent(text(s), 2))
case node.Data == "a":
return fmt.Sprintf("%s (%s) ", s.Text(), s.AttrOr("href", "missing link"))
case node.Data == "li":
return fmt.Sprintf(" • %s\n", contents(s))
case node.Data == "ul":
return fmt.Sprintf("%s\n", nodes(s))
case node.Data == "code":
return fmt.Sprintf("\033[1m%s\033[0m ", s.Text())
case node.Type == html.TextNode:
return strings.TrimSpace(node.Data)
default:
return ""
}
}
示例2: Create
func (c Boot24Crawler) Create(s *goquery.Selection) Entry {
link := s.AttrOr("href", "none")
price := s.Find(".sr-price").Text()
desc := s.Find(".sr-objektbox-us").Text()
details := strings.Fields(s.Find(".details_left").Text())
boatType := details[0]
manufactureDate := details[3]
condition := details[5]
return Entry{
Condition: condition,
Description: desc,
Link: link,
ManufactureDate: manufactureDate,
Price: price,
Type: boatType,
}
}