当前位置: 首页>>代码示例>>Golang>>正文


Golang Selection.Is方法代码示例

本文整理汇总了Golang中github.com/PuerkitoBio/goquery.Selection.Is方法的典型用法代码示例。如果您正苦于以下问题:Golang Selection.Is方法的具体用法?Golang Selection.Is怎么用?Golang Selection.Is使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/PuerkitoBio/goquery.Selection的用法示例。


在下文中一共展示了Selection.Is方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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()
	}
}
开发者ID:liangmiaoling,项目名称:spider_lib,代码行数:9,代码来源:baidunews.go

示例2: encuentraGrupo

func encuentraGrupo(tabla *goquery.Selection) (grupo int) {
	var anterior *goquery.Selection
	for anterior = tabla.Prev(); anterior.Length() > 0 && grupo == 0; anterior = anterior.Prev() {
		if !anterior.Is("div") {
			log.Fatal(errors.New("No se encontró curso para la tabla"))
		}
		strongs := anterior.Find("strong")
		if strongs.Length() != 1 {
			continue
		}
		hayMatch, err := regexp.MatchString("Grupo [0-9]+", strongs.Text())
		if err != nil {
			mataPrograma("Morí en encuentraGrupo regex", err)
		}
		if hayMatch {
			tokens := strings.Split(strongs.Text(), " ")
			grupo, err = strconv.Atoi(tokens[1])
			if err != nil {
				mataPrograma("Morí en encuentraGrupo hayMatch", err)
			}
		}
	}
	return
}
开发者ID:sainoba,项目名称:mifciencias,代码行数:24,代码来源:cursos.go

示例3: scoreNode

func (d *Document) scoreNode(s *goquery.Selection) *candidate {
	contentScore := d.classWeight(s)
	if s.Is("div") {
		contentScore += 5
	} else if s.Is("blockquote,form") {
		contentScore = 3
	} else if s.Is("th") {
		contentScore -= 5
	}

	return &candidate{s, float32(contentScore)}
}
开发者ID:jpoehls,项目名称:feedmailer,代码行数:12,代码来源:readability.go

示例4: cleanConditionally

func (d *Document) cleanConditionally(s *goquery.Selection, selector string) {
	if !d.CleanConditionally {
		return
	}

	s.Find(selector).Each(func(i int, s *goquery.Selection) {
		node := s.Get(0)
		weight := float32(d.classWeight(s))
		contentScore := float32(0)

		if c, ok := d.candidates[node]; ok {
			contentScore = c.score
		}

		if weight+contentScore < 0 {
			removeNodes(s)
			Logger.Printf("Conditionally cleaned %s%s with weight %f and content score %f\n", node.Data, getName(s), weight, contentScore)
			return
		}

		text := s.Text()
		if strings.Count(text, ",") < 10 {
			counts := map[string]int{
				"p":     s.Find("p").Length(),
				"img":   s.Find("img").Length(),
				"li":    s.Find("li").Length() - 100,
				"a":     s.Find("a").Length(),
				"embed": s.Find("embed").Length(),
				"input": s.Find("input").Length(),
			}

			contentLength := len(strings.TrimSpace(text))
			linkDensity := d.getLinkDensity(s)
			remove := false
			reason := ""

			if counts["img"] > counts["p"] {
				reason = "too many images"
				remove = true
			} else if counts["li"] > counts["p"] && !s.Is("ul,ol") {
				reason = "more <li>s than <p>s"
				remove = true
			} else if counts["input"] > int(counts["p"]/3.0) {
				reason = "less than 3x <p>s than <input>s"
				remove = true
			} else if contentLength < d.MinTextLength && (counts["img"] == 0 || counts["img"] > 2) {
				reason = "too short content length without a single image"
				remove = true
			} else if weight < 25 && linkDensity > 0.2 {
				reason = fmt.Sprintf("too many links for its weight (%f)", weight)
				remove = true
			} else if weight >= 25 && linkDensity > 0.5 {
				reason = fmt.Sprintf("too many links for its weight (%f)", weight)
				remove = true
			} else if (counts["embed"] == 1 && contentLength < 75) || counts["embed"] > 1 {
				reason = "<embed>s with too short a content length, or too many <embed>s"
				remove = true
			}

			if remove {
				Logger.Printf("Conditionally cleaned %s%s with weight %f and content score %f because it has %s\n", node.Data, getName(s), weight, contentScore, reason)
				removeNodes(s)
			}
		}
	})
}
开发者ID:jpoehls,项目名称:feedmailer,代码行数:66,代码来源:readability.go


注:本文中的github.com/PuerkitoBio/goquery.Selection.Is方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。