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


Golang Selection.Each方法代码示例

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


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

示例1: parseColors

func parseColors(s *goquery.Selection) string {
	colors := ""
	s.Each(func(i int, s *goquery.Selection) {
		colors += s.Text()
	})
	return colors
}
开发者ID:josephmisiti,项目名称:mac-crawler,代码行数:7,代码来源:crawl_products.go

示例2: parseTranslations

func parseTranslations(elements *goquery.Selection) (results []Translation) {
	elements.Each(func(index int, element *goquery.Selection) {
		results = append(results, Translation{parseMeaning(element), parseHref(element), parsePhrase(element)})
	})

	return
}
开发者ID:alexander-heimbuch,项目名称:linguee-alfred-workflow,代码行数:7,代码来源:linguee.go

示例3: dropTag

func (this *parser) dropTag(selection *goquery.Selection) {
	selection.Each(func(i int, s *goquery.Selection) {
		node := s.Get(0)
		node.Data = s.Text()
		node.Type = html.TextNode
	})
}
开发者ID:hotei,项目名称:GoOse,代码行数:7,代码来源:parser.go

示例4: JoinNodesWithSpace

func JoinNodesWithSpace(s *goquery.Selection) string {
	texts := []string{}
	s.Each(func(i int, s *goquery.Selection) {
		texts = append(texts, s.Text())
	})
	return strings.Join(texts, " ")
}
开发者ID:squat,项目名称:drae,代码行数:7,代码来源:scrape.go

示例5: parseRegions

func parseRegions(regionTags *goquery.Selection) []string {
	result := make([]string, 0, regionTags.Length())
	regionTags.Each(func(n int, s *goquery.Selection) {
		result = append(result, s.Text())
	})

	return result
}
开发者ID:Jenyay,项目名称:streetlist,代码行数:8,代码来源:streetparser.go

示例6: 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))
		}
	})
}
开发者ID:jpoehls,项目名称:feedmailer,代码行数:10,代码来源:readability.go

示例7: filtraLigasP

func filtraLigasP(seleccion *goquery.Selection) (planesGo []*goquery.Selection) {
	seleccion.Each(func(i int, anchor *goquery.Selection) {
		if attr, existe := anchor.Attr("href"); existe {
			if empata, _ := regexp.MatchString("/docencia/horarios/indiceplan/", attr); empata {
				planesGo = append(planesGo, anchor)
			}
		}
	})
	return
}
开发者ID:sainoba,项目名称:mifciencias,代码行数:10,代码来源:planes.go

示例8: hitCaches

func (e *extractImages) hitCaches(imgs *goquery.Selection, attr string) []*Image {
	var hits []*Image

	imgs.Each(func(i int, img *goquery.Selection) {
		hit := e.hitCache(img, attr)
		if hit != nil {
			i := *hit
			i.Sel = img
			hits = append(hits, &i)
		}
	})

	return hits
}
开发者ID:oudommeas,项目名称:swan,代码行数:14,代码来源:extract_images.go

示例9: Links

func (f *follower) Links(sel *goquery.Selection) []string {
	if f.Selector != "" {
		sel = sel.Find(f.Selector)
	}

	var links []string

	sel.Each(func(i int, s *goquery.Selection) {
		for _, ext := range f.DataExtractors {
			links = append(links, ext.Extract(s))
		}
	})

	return links
}
开发者ID:pilu,项目名称:robin,代码行数:15,代码来源:follower.go

示例10: Extract

// Extract returns Items querying `sel` using ItemExtractor's DataExtractors
func (e *ItemExtractor) Extract(sel *goquery.Selection) Items {
	var items Items

	if e.Selector != "" {
		sel = sel.Find(e.Selector)
	}

	sel.Each(func(i int, s *goquery.Selection) {
		item := make(Item)
		for name, ext := range e.DataExtractors {
			item[name] = ext.Extract(s)
		}
		items = append(items, item)
	})

	return items

}
开发者ID:pilu,项目名称:scrapesburys,代码行数:19,代码来源:extractor.go

示例11: GetVideos

func (ve *VideoExtractor) GetVideos(article *Article) *set.Set {
	doc := article.Doc
	var nodes *goquery.Selection
	for _, videoTag := range videoTags {
		tmpNodes := doc.Find(videoTag)
		if nodes == nil {
			nodes = tmpNodes
		} else {
			nodes.Union(tmpNodes)
		}
	}

	nodes.Each(func(i int, node *goquery.Selection) {
		tag := node.Get(0).DataAtom.String()
		var movie video
		switch tag {
		case "video":
			movie = ve.getVideoTag(node)
			break
		case "embed":
			movie = ve.getEmbedTag(node)
			break
		case "object":
			movie = ve.getObjectTag(node)
			break
		case "iframe":
			movie = ve.getIFrame(node)
			break
		default:
			{
			}
		}

		if movie.src != "" {
			ve.movies.Add(movie)
		}
	})

	return ve.movies
}
开发者ID:hotei,项目名称:GoOse,代码行数:40,代码来源:videos.go

示例12: pullMimes

func pullMimes(w io.Writer, sel *goquery.Selection) {
	sel.Each(func(_ int, s *goquery.Selection) {
		tds := s.Find("td")

		style, ok := tds.Attr("style")
		if ok && strings.Contains(style, "cursor:") {
			return
		}

		extNode := tds.WrapNode(tds.Get(0))
		html, _ := extNode.Html()

		ext := strings.Split(extNode.Text(), "\n")
		if len(ext) < 2 {
			return
		}

		var refs []string

		tds.WrapNode(tds.Get(2)).Find("a").Each(func(_ int, sel *goquery.Selection) {
			href, ok := sel.Attr("href")
			if !ok {
				return
			}

			if !strings.HasPrefix(href, "http") {
				return
			}

			refs = append(refs, fmt.Sprintf("%q", href))
		})

		if len(refs) > 0 {
			fmt.Fprintf(w, " AddExtensionType(%q, %q, %s)\n", html, strings.TrimSpace(ext[1]), strings.Join(refs, ","))
			return
		}

		fmt.Fprintf(w, " AddExtensionType(%q, %q)\n", html, strings.TrimSpace(ext[1]))
	})
}
开发者ID:influx6,项目名称:gu,代码行数:40,代码来源:generate.go

示例13: Tianhuan

func Tianhuan(templete *Node, src *goquery.Selection, m map[string]interface{}) error {

	mySelect, properties, err := templete.GetSelect(SELECT)
	if err != nil {
		return err
	}
	var ser *goquery.Selection
	if mySelect == "" {
		fmt.Println("value-of 需要填写select属性")
		ser = src
	} else {
		ser = src.Find(mySelect)
	}

	var nodes = make([]*goquery.Selection, 0)
	if len(ser.Nodes) == 0 {

		return errors.New(mySelect + ":未搜索到数据")
	}
	if properties != nil {

		ser.EachWithBreak(func(i int, s *goquery.Selection) bool {
			if properties.Index != 0 {
				if properties.Index == i+1 { //index
					nodes = append(nodes, s)
					return false
				}
				return true
			}
			var lenn = len(s.Get(0).Attr)
			//			var ma bool = false
			for b := 0; b < lenn; b++ {
				if _, ok := properties.Property[s.Get(0).Attr[b].Key]; ok {
					for _, v := range properties.Property[s.Get(0).Attr[b].Key] {
						if strings.Contains(v, ".*") {
							if ok, er := regexp.Match(v, []byte(s.Get(0).Attr[b].Val)); er != nil {
								return false
							} else {
								if ok {
									if Ifok(properties, s.Get(0), b) {
										nodes = append(nodes, s)
									}
									return true
								}
							}
						}

						if s.Get(0).Attr[b].Val == v {
							if Ifok(properties, s.Get(0), b) {
								nodes = append(nodes, s)
								return true
							}
						}
					}
				}

			}
			return true
		})

		//abandon
		_, pro, err := templete.GetSelect(ABANDON)
		if err != nil {
			return err
		}
		if pro != nil {
			for k, _ := range pro.Property {
				nodes = nodesDelete(nodes, GetSelectsByValue(pro.Property[k], nodes, k))
			}

		}

	} else {
		ser.Each(func(i int, s *goquery.Selection) {
			nodes = append(nodes, s)
		})
	}

	//not 操作符
	nodes = notInstructionCharacter(properties, nodes)

	fmt.Println("***************************")
	for _, vvv := range nodes {
		fmt.Println(vvv.Get(0).Attr, vvv.Get(0).Data)
	}
	fmt.Println("------------------------------")
	var index int = 0
	for _, matchLabel := range templete.Children {
		switch matchLabel.LabelName {
		case STORAGE: //取值
			if 0 != MatchMap(nodes, matchLabel, m, &index, nil) {
				break
			}
		case VALUEOF: //查找值
			var bb *goquery.Selection
			var la = make([]*html.Node, 0)
			for _, ll := range nodes {
				la = append(la, ll.Get(0))
			}
			bb.Nodes = la
//.........这里部分代码省略.........
开发者ID:slygo,项目名称:360baosdk,代码行数:101,代码来源:match.go

示例14: OutPutTianhuan

func OutPutTianhuan(templete *Node, src *goquery.Selection, m map[string]interface{}) error {

	mySelect, properties, err := templete.GetSelect(SELECT)
	if err != nil {
		return err
	}
	var ser *goquery.Selection
	if mySelect == "" {
		fmt.Println("value-of 需要填写select属性")
		ser = src
	} else {
		ser = src.Find(mySelect)
	}

	var nodes = make([]*goquery.Selection, 0)
	if len(ser.Nodes) == 0 {

		return errors.New(mySelect + ":未搜索到数据")
	}
	if properties != nil {

		ser.EachWithBreak(func(i int, s *goquery.Selection) bool {
			if properties.Index != 0 {
				if properties.Index == i+1 { //index
					nodes = append(nodes, s)
					return false
				}
				return true
			}
			var lenn = len(s.Get(0).Attr)
			//			var ma bool = false
			for b := 0; b < lenn; b++ {
				if _, ok := properties.Property[s.Get(0).Attr[b].Key]; ok {

					for _, v := range properties.Property[s.Get(0).Attr[b].Key] {

						if strings.Contains(v, ".*") {
							if ok, er := regexp.Match(v, []byte(s.Get(0).Attr[b].Val)); er != nil {
								return false
							} else {
								if ok {
									if Ifok(properties, s.Get(0), b) {
										nodes = append(nodes, s)
									}
									return true
								}
							}
						}

						if s.Get(0).Attr[b].Val == v {
							if Ifok(properties, s.Get(0), b) {
								nodes = append(nodes, s)
								return true
							}
						}
					}
				}

			}
			return true
		})

		//abandon
		_, pro, err := templete.GetSelect(ABANDON)
		if err != nil {
			return err
		}
		if pro != nil {
			for k, _ := range pro.Property {
				nodes = nodesDelete(nodes, GetSelectsByValue(pro.Property[k], nodes, k))
			}

		}

	} else {
		ser.Each(func(i int, s *goquery.Selection) {
			nodes = append(nodes, s)
		})
	}

	//not 操作符
	nodes = notInstructionCharacter(properties, nodes)

	var index int = 0
	for _, matchLabel := range templete.Children {
		switch matchLabel.LabelName {
		case TOVALUE:
			//fmt.Println("修改值中")
			FillingValue(matchLabel, m, nodes, &index)
		case LAYER: //改变map
			path := matchLabel.Attr["path"] //path有值
			var usem interface{}
			usem = GetValueFormMapByLayer(m, path)
			if usem != nil {
				//填网页
				FillingValueByChildren(matchLabel, usem, nodes, &index)
			}

		default:
			fmt.Println("模板标签书写错误了吧")
//.........这里部分代码省略.........
开发者ID:slygo,项目名称:360baosdk,代码行数:101,代码来源:outputdealwith.go


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