本文整理汇总了Golang中github.com/PuerkitoBio/goquery.Selection类的典型用法代码示例。如果您正苦于以下问题:Golang Selection类的具体用法?Golang Selection怎么用?Golang Selection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Selection类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: getSelectionSignature
// this function returns some specific signature of a selection
// so it can be easy found to get data quickly next time
func getSelectionSignature(s *goquery.Selection) string {
var signature string
tag, _ := goquery.OuterHtml(s)
pos := strings.Index(tag, ">")
if pos > -1 {
tag = tag[1:pos]
} else {
return ""
}
signature = convertTagToJqueryFormat(tag, s)
s.Parents().Each(func(i int, sec *goquery.Selection) {
ohtml, _ := goquery.OuterHtml(sec)
pos := strings.Index(ohtml, ">")
if pos > -1 {
ohtml = ohtml[1:pos]
}
tag := convertTagToJqueryFormat(ohtml, sec)
signature = tag + " " + signature
})
return signature
}
开发者ID:Gelembjuk,项目名称:articletext,代码行数:33,代码来源:selectionpath.go
示例2: isHighLinkDensity
//checks the density of links within a node, is there not much text and most of it contains bad links?
//if so it's no good
func (this *contentExtractor) isHighLinkDensity(node *goquery.Selection) bool {
links := node.Find("a")
if links == nil || links.Size() == 0 {
return false
}
text := node.Text()
words := strings.Split(text, " ")
nwords := len(words)
sb := make([]string, 0)
links.Each(func(i int, s *goquery.Selection) {
linkText := s.Text()
sb = append(sb, linkText)
})
linkText := strings.Join(sb, "")
linkWords := strings.Split(linkText, " ")
nlinkWords := len(linkWords)
nlinks := links.Size()
linkDivisor := float64(nlinkWords) / float64(nwords)
score := linkDivisor * float64(nlinks)
if this.config.debug {
logText := ""
if len(node.Text()) >= 51 {
logText = node.Text()[0:50]
} else {
logText = node.Text()
}
log.Printf("Calculated link density score as %1.5f for node %s\n", score, logText)
}
if score > 1.0 {
return true
}
return false
}
开发者ID:ngs,项目名称:GoOse,代码行数:36,代码来源:extractor.go
示例3: commonPrase
func (b baiduNews) commonPrase(ctx *Context) (infoStr string) {
body := ctx.GetDom().Find("body")
var info *goquery.Selection
if h1s := body.Find("h1"); len(h1s.Nodes) != 0 {
for i := 0; i < len(h1s.Nodes); i++ {
info = b.findP(h1s.Eq(i))
}
} else if h2s := body.Find("h2"); len(h2s.Nodes) != 0 {
for i := 0; i < len(h2s.Nodes); i++ {
info = b.findP(h2s.Eq(i))
}
} else if h3s := body.Find("h3"); len(h3s.Nodes) != 0 {
for i := 0; i < len(h3s.Nodes); i++ {
info = b.findP(h3s.Eq(i))
}
} else {
info = body.Find("body")
}
infoStr, _ = info.Html()
// 清洗HTML
infoStr = CleanHtml(infoStr, 5)
return
}
开发者ID:liangmiaoling,项目名称:spider_lib,代码行数:26,代码来源:baidunews.go
示例4: 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
示例5: attrOrDefault
// attributeOrDefault reads an attribute and returns it or the default value when it's empty.
func (bow *Browser) attrOrDefault(name, def string, sel *goquery.Selection) string {
a, ok := sel.Attr(name)
if ok {
return a
}
return def
}
开发者ID:haruyama,项目名称:surf,代码行数:8,代码来源:browser.go
示例6: commonPrase
func (b baiduNews) commonPrase(resp *context.Response) (infoStr string) {
body := resp.GetDom().Find("body")
var info *goquery.Selection
if h1s := body.Find("h1"); len(h1s.Nodes) != 0 {
for i := 0; i < len(h1s.Nodes); i++ {
info = b.findP(h1s.Eq(i))
}
} else if h2s := body.Find("h2"); len(h2s.Nodes) != 0 {
for i := 0; i < len(h2s.Nodes); i++ {
info = b.findP(h2s.Eq(i))
}
} else if h3s := body.Find("h3"); len(h3s.Nodes) != 0 {
for i := 0; i < len(h3s.Nodes); i++ {
info = b.findP(h3s.Eq(i))
}
} else {
info = body.Find("body")
}
// 去除标签
// info.RemoveFiltered("script")
// info.RemoveFiltered("style")
infoStr, _ = info.Html()
// 清洗HTML
infoStr = CleanHtml(infoStr, 5)
return
}
开发者ID:timesking,项目名称:spider_lib,代码行数:29,代码来源:baidunews.go
示例7: scrapPayload
func scrapPayload(s *goquery.Selection, n int) string {
url, ok := s.Find("a").Attr("href")
if !ok {
die("unable to find URL for scrapping")
}
return scrapPayloadURL("https://developer.github.com"+url, n)
}
开发者ID:jrdnull,项目名称:gh,代码行数:7,代码来源:generate_payloads.go
示例8: 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
示例9: 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
示例10: parseGamePosition
func parseGamePosition(selection *goquery.Selection) (position int) {
positionString := strings.TrimSpace(selection.Children().First().Text())
var err error
position, err = strconv.Atoi(strings.TrimSpace(positionString))
helper.HandleFatalError("parsing game position failed:", err)
return
}
开发者ID:sejoharp,项目名称:kickerstats,代码行数:7,代码来源:gameParser.go
示例11: ScrapeExamples
func ScrapeExamples(s *goquery.Selection) []string {
examples := []string{}
s.Find("span.h").Each(func(i int, s *goquery.Selection) {
examples = append(examples, s.Text())
})
return examples
}
开发者ID:squat,项目名称:drae,代码行数:7,代码来源:scrape.go
示例12: extractCredits
func extractCredits(selection *goquery.Selection) string {
if result := trim(selection.Find(".credits").Text()); strings.Contains(result, "#") {
return "0"
} else {
return result
}
}
开发者ID:tevjef,项目名称:NJIT-Course-Tracker,代码行数:7,代码来源:main.go
示例13: extractCourseDescription
func extractCourseDescription(selection *goquery.Selection) string {
url := trim(fmt.Sprintln(selection.Find(".catalogdescription a").AttrOr("href", "")))
fmt.Println("LOGGING URL", url)
client := http.Client{}
req, _ := http.NewRequest("GET", "http://catalog.njit.edu/ribbit/index.cgi?format=html&page=fsinjector.rjs&fullpage=true", nil)
req.Header.Add("Referer", url)
resp, err := client.Do(req)
if err != nil {
return ""
}
if resp != nil {
defer resp.Body.Close()
}
body, _ := ioutil.ReadAll(resp.Body)
//checkError(err)
result := substringAfter(string(body), "courseblockdesc")
if len(result) < 4 {
return ""
}
result = substringBefore(result[3:], "<b")
if string(result[0]) == "<" || strings.Contains(result, "at SISConnxService") {
return ""
}
result = strings.Replace(result, "\\\"", "\"", -1)
doc, _ := goquery.NewDocumentFromReader(strings.NewReader(result))
return trim(doc.Text())
}
开发者ID:tevjef,项目名称:NJIT-Course-Tracker,代码行数:30,代码来源:main.go
示例14: convertTagToJqueryFormat
func convertTagToJqueryFormat(tag string, s *goquery.Selection) string {
tagitself := tag
pos := strings.Index(tag, " ")
if pos > -1 {
tagitself = tag[0:pos]
} else {
return tag
}
class, found := s.Attr("class")
if found && class != "" {
pos := strings.Index(class, " ")
// leave only a first class from a list
if pos > -1 {
class = class[0:pos]
}
tagitself = tagitself + "." + class
}
return tagitself
}
开发者ID:Gelembjuk,项目名称:articletext,代码行数:26,代码来源:selectionpath.go
示例15: testList
func testList(t *testing.T, list *goquery.Selection) {
list.Find("ul").Each(func(_ int, items *goquery.Selection) {
testList(t, items)
items.RemoveFiltered("ul")
})
checkAlphabeticOrder(t, list)
}
开发者ID:phpsong,项目名称:awesome-phalcon,代码行数:7,代码来源:repo_test.go
示例16: delAttr
func (this *parser) delAttr(selection *goquery.Selection, attr string) {
idx := this.indexOfAttribute(selection, attr)
if idx > -1 {
node := selection.Get(0)
node.Attr = append(node.Attr[:idx], node.Attr[idx+1:]...)
}
}
开发者ID:hotei,项目名称:GoOse,代码行数:7,代码来源:parser.go
示例17: 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
}
开发者ID:fclairamb,项目名称:drone,代码行数:29,代码来源:generate-docs.go
示例18: name
func (this *parser) name(selector string, selection *goquery.Selection) string {
value, exists := selection.Attr(selector)
if exists {
return value
}
return ""
}
开发者ID:hotei,项目名称:GoOse,代码行数:7,代码来源:parser.go
示例19: classWeight
func (d *Document) classWeight(s *goquery.Selection) int {
weight := 0
if !d.WeightClasses {
return weight
}
class, _ := s.Attr("class")
id, _ := s.Attr("id")
if class != "" {
if negativeRegexp.MatchString(class) {
weight -= 25
}
if positiveRegexp.MatchString(class) {
weight += 25
}
}
if id != "" {
if negativeRegexp.MatchString(id) {
weight -= 25
}
if positiveRegexp.MatchString(id) {
weight += 25
}
}
return weight
}
开发者ID:jpoehls,项目名称:feedmailer,代码行数:31,代码来源:readability.go
示例20: 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
注:本文中的github.com/PuerkitoBio/goquery.Selection类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论