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


Golang Selection.Map方法代码示例

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


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

示例1: getBusListfrmMTC

func getBusListfrmMTC(bussite string) ([]string, error) {
	var b *goquery.Document
	var bb *goquery.Selection
	var fn func(int, *goquery.Selection) string
	b, e := goquery.NewDocument(bussite)
	if e != nil {
		return nil, e
	}
	bb = b.Find("Option")
	bb = bb.Not(":empty")
	fn = func(i int, s *goquery.Selection) string {
		return s.Text()
	}
	return bb.Map(fn), nil
}
开发者ID:ajjaic,项目名称:scrapmtc,代码行数:15,代码来源:gettingbuslist.go

示例2: TrimmedTexts

func TrimmedTexts(s *goquery.Selection) []string {
	return s.Map(func(_ int, s *goquery.Selection) string {
		return strings.TrimSpace(s.Text())
	})
}
开发者ID:tsinghua-io,项目名称:api-server,代码行数:5,代码来源:goquery.go

示例3: ExtractBodyFromDocument

func ExtractBodyFromDocument(doc *gq.Document, fromJSON bool, includeTitle bool) *m.ExtractedBody {
	msg := new(m.Messages)

	var paragraphs *gq.Selection
	if fromJSON {
		paragraphs = doc.Find("p")
	} else {
		if len(doc.Find(".longform-body").Nodes) == 0 {
			paragraphs = doc.Find("div[itemprop=articleBody] > p")
		} else {
			paragraphs = doc.Find("div[itemprop=articleBody] > .longform-body > p")
		}
	}

	// remove contact info at the end of the article (might not be needed any more when parsing
	// HTML from JSON?)
	paragraphs.Find("span.-newsgate-paragraph-cci-endnote-contact-").Remove()
	paragraphs.Find("span.-newsgate-paragraph-cci-endnote-contrib-").Remove()

	ignoreRemaining := false
	paragraphStrings := paragraphs.Map(func(i int, paragraph *gq.Selection) string {
		if ignoreRemaining {
			return ""
		}
		for _, selector := range [...]string{"span.-newsgate-character-cci-tagline-name-", "span.-newsgate-paragraph-cci-infobox-head-"} {
			if el := paragraph.Find(selector); el.Length() > 0 {
				ignoreRemaining = true
				return ""
			}
		}

		text := strings.TrimSpace(paragraph.Text())

		if worthy, _ := classify.IsWorthyParagraph(text); !worthy {
			return ""
		}

		//marker := ""

		for _, selector := range [...]string{"span.-newsgate-paragraph-cci-subhead-lead-", "span.-newsgate-paragraph-cci-subhead-"} {
			if el := paragraph.Find(selector); el.Length() > 0 {
				//marker = "### "
				return ""
				break
			}
		}

		return text
	})

	if len(paragraphStrings) > 0 {
		paragraphStrings[0] = dateline.RmDateline(paragraphStrings[0])
	}

	content := make([]string, 0, len(paragraphStrings)+1)
	if includeTitle {
		title := ExtractTitleFromDocument(doc)
		content = append(content, title)
	}

	content = append(content, withoutEmptyStrings(paragraphStrings)...)

	body := strings.Join(content, "\n")
	recipeData, recipeMsg := recipe_parsing.ExtractRecipes(doc)
	msg.AddMessages("recipes", recipeMsg)
	extracted := m.ExtractedBody{body, recipeData, msg}
	return &extracted
}
开发者ID:michigan-com,项目名称:newsfetch,代码行数:68,代码来源:parse.go


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