本文整理汇总了Golang中github.com/PuerkitoBio/goquery.Selection.Parent方法的典型用法代码示例。如果您正苦于以下问题:Golang Selection.Parent方法的具体用法?Golang Selection.Parent怎么用?Golang Selection.Parent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/PuerkitoBio/goquery.Selection
的用法示例。
在下文中一共展示了Selection.Parent方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getEmbedTag
func (ve *VideoExtractor) getEmbedTag(node *goquery.Selection) video {
parent := node.Parent()
if parent != nil {
parentTag := parent.Get(0).DataAtom.String()
if parentTag == "object" {
return ve.getObjectTag(node)
}
}
return ve.getVideo(node)
}
示例2: removeNodes
func removeNodes(s *goquery.Selection) {
s.Each(func(i int, s *goquery.Selection) {
parent := s.Parent()
if parent.Length() == 0 {
// TODO???
} else {
parent.Get(0).RemoveChild(s.Get(0))
}
})
}
示例3: findP
func (b baiduNews) findP(html *goquery.Selection) *goquery.Selection {
if html.Is("body") {
return html
} else if result := html.Parent().Find("p"); len(result.Nodes) == 0 {
return b.findP(html.Parent())
} else {
return html.Parent()
}
}
示例4: get_sesiones
func get_sesiones(selection_strong *goquery.Selection) (hubo bool) {
div_selection := selection_strong.Parent()
selection := div_selection.Next()
var table_selction *goquery.Selection
hubo = false
for {
tipo := goquery.NodeName(selection)
if tipo == "table" {
hubo = true
table_selction = selection
break
} else if tipo == "div" && len(selection.Find("strong").Nodes) != 0 {
return
} else if len(selection.Nodes) == 0 {
return
}
selection = selection.Next()
}
tr_selection := table_selction.Find("tr")
for idx_tr := 0; idx_tr < len(tr_selection.Nodes); idx_tr++ {
td_selection := tr_selection.Eq(idx_tr).Find("td")
// puesto, nombre, dias, horas, salon
if len(td_selection.Nodes) > 5 {
fmt.Println(td_selection.Text())
hubo = false
return
}
for idx_td := 0; idx_td < len(td_selection.Nodes); idx_td++ {
if strings.TrimSpace(td_selection.Eq(idx_td).Text()) == "" {
hubo = false
return
}
}
}
return
}
示例5: checkLarge
func (e *extractImages) checkLarge(s *goquery.Selection, depth uint) bool {
imgs := s.FindMatcher(imgTags).FilterFunction(
func(i int, s *goquery.Selection) bool {
if i > 30 {
return false
}
src, ok := s.Attr("src")
if !ok {
return false
}
for _, s := range badImgNames {
if strings.Contains(src, s) {
return false
}
}
return true
}).FilterFunction(
func(i int, s *goquery.Selection) bool {
img := e.hitCache(s, "src")
if img == nil {
return false
}
return true
})
rimgs := e.hitCaches(imgs, "src")
if len(rimgs) > 0 {
var bestImg *Image
cnt := 0
initialArea := 0.0
maxScore := 0.0
if len(rimgs) > 30 {
rimgs = rimgs[:30]
}
for _, i := range rimgs {
shouldScore := ((depth >= 1 && i.Width > 300) || depth == 0) &&
i.Width > minImgWidth &&
!e.isBannerDims(i)
if !shouldScore {
continue
}
area := float64(i.Width * i.Height)
score := 0.0
if initialArea == 0.0 {
initialArea = area * 1.48
score = 1.0
} else {
areaDiff := area / initialArea
sequenceScore := 1.0 / float64(cnt)
score = sequenceScore * areaDiff
}
if score > maxScore {
maxScore = score
bestImg = i
}
cnt++
}
if bestImg != nil {
bestImg.Confidence = uint(100 / len(rimgs))
e.a.Img = bestImg
return true
}
}
if depth > 2 {
return false
}
prev := s.Prev()
if prev.Length() > 0 {
return e.checkLarge(prev, depth)
}
par := s.Parent()
if par.Length() > 0 {
return e.checkLarge(par, depth+1)
}
return false
}
示例6: findParentWithHref
func findParentWithHref(s *goquery.Selection) *goquery.Selection {
// TODO: Do loop to find first parent with link
return s.Parent()
}