本文整理汇总了Golang中github.com/PuerkitoBio/goquery.Selection.SetAttr方法的典型用法代码示例。如果您正苦于以下问题:Golang Selection.SetAttr方法的具体用法?Golang Selection.SetAttr怎么用?Golang Selection.SetAttr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/PuerkitoBio/goquery.Selection
的用法示例。
在下文中一共展示了Selection.SetAttr方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: toPage
// toPage is a helper function that accepts an anchor
// tag referencing a markdown file, parsing the markdown
// file and returning a page to be included in our docs.
func toPage(site *Site, el *goquery.Selection) (*Page, error) {
// follow the link to see if this is a page
// that should be added to our documentation.
href, ok := el.Attr("href")
if !ok || href == "#" {
return nil, nil
}
// read the markdown file, convert to html and
// read into a dom element.
doc, err := toDocument(filepath.Join(site.base, href))
if err != nil {
return nil, err
}
// convert the extension from markdown to
// html, in preparation for type conversion.
href = strings.Replace(href, ".md", ".html", -1)
el.SetAttr("href", href)
page := &Page{}
page.Href = href
page.html, err = doc.Html()
return page, err
}
示例2: changeHtmlPro
func changeHtmlPro(node *goquery.Selection, key, value []string) bool {
if node == nil {
return false
}
if len(key) != len(value) {
return false
}
for i := 0; i < len(key); i++ {
node.SetAttr(key[0], value[0])
}
return true
}
示例3: describeDocumentNode
// describe a text inside a node and add description as pseudo attributes
func describeDocumentNode(s *goquery.Selection) *goquery.Selection {
var totalcountofgoodsentences int
var totalcountofcorrectsentences int
var maxcountofflatsentences int
countchildren := s.Children().Length()
var sd TextDescription
if countchildren > 0 {
// for each child node check if to remove or not
s.Children().Each(func(i int, sec *goquery.Selection) {
// go deeper recursively
describeDocumentNode(sec)
// aggregate data to set to a node
totalcountofgoodsentences += getNumbericAttribute(sec, "totalcountofgoodsentences")
totalcountofcorrectsentences += getNumbericAttribute(sec, "totalcountofcorrectsentences")
countsentences := getNumbericAttribute(sec, "maxcountofflatsentences")
if countsentences > maxcountofflatsentences {
maxcountofflatsentences = countsentences
}
})
// describe sentences in this html tag only, drop child nodes
secclone := getSelectionWihoutChildren(s)
sd = describeSentences(secclone)
totalcountofgoodsentences += sd.CountGoodSentences
totalcountofcorrectsentences += sd.CountCorrectSentences
if sd.CountGoodSentences > maxcountofflatsentences {
maxcountofflatsentences = sd.CountGoodSentences
}
} else {
// no child nodes
//fmt.Println(s.Text())
sd = describeSentences(s)
totalcountofgoodsentences = sd.CountGoodSentences
maxcountofflatsentences = sd.CountGoodSentences
totalcountofcorrectsentences = sd.CountCorrectSentences
}
//fmt.Printf("set totalcountofgoodsentences ")
// set attributes for the node
s.SetAttr("countsentences", strconv.Itoa(sd.CountSentences))
s.SetAttr("averagewords", strconv.Itoa(sd.AverageWords))
s.SetAttr("countgoodsentences", strconv.Itoa(sd.CountGoodSentences))
s.SetAttr("countlongsentences", strconv.Itoa(sd.CountLongSentences))
s.SetAttr("totalcountofgoodsentences", strconv.Itoa(totalcountofgoodsentences))
s.SetAttr("totalcountofcorrectsentences", strconv.Itoa(totalcountofcorrectsentences))
s.SetAttr("maxcountofflatsentences", strconv.Itoa(maxcountofflatsentences))
return s
}