• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang goquery.NewDocumentFromNode函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: Parse

// Parse 获取url对应的资源并根据规则进行解析
func (this *RedditLogic) Parse(redditUrl string) error {
	redditUrl = strings.TrimSpace(redditUrl)
	if redditUrl == "" {
		redditUrl = this.domain + this.golang
	} else if !strings.HasPrefix(redditUrl, "https") {
		redditUrl = "https://" + redditUrl
	}

	var (
		doc *goquery.Document
		err error
	)

	// if doc, err = goquery.NewDocument(redditUrl); err != nil {
	if doc, err = this.newDocumentFromResp(redditUrl); err != nil {
		logger.Errorln("goquery reddit newdocument error:", err)
		return err
	}

	// 最后面的先入库处理
	resourcesSelection := doc.Find("#siteTable .link")

	for i := resourcesSelection.Length() - 1; i >= 0; i-- {
		err = this.dealRedditOneResource(goquery.NewDocumentFromNode(resourcesSelection.Get(i)).Selection)

		if err != nil {
			logger.Errorln(err)
		}
	}

	return err
}
开发者ID:studygolang,项目名称:studygolang,代码行数:33,代码来源:reddit.go


示例2: GenerateDocument

func GenerateDocument(rawData []byte) *goquery.Document {
	utf8String := toUtf8(rawData)
	utf8byteArray := []byte(utf8String)
	node, err := html.Parse(bytes.NewReader(utf8byteArray))
	helper.HandleFatalError("document generation failed:", err)
	return goquery.NewDocumentFromNode(node)
}
开发者ID:sejoharp,项目名称:kickerstats,代码行数:7,代码来源:interfaces.go


示例3: visitUrl

// Process the response for a URL.
func (this *worker) visitUrl(res *http.Response) []*url.URL {
	var doc *goquery.Document
	var harvested []*url.URL
	var doLinks bool

	// Load a goquery document and call the visitor function
	if node, e := html.Parse(res.Body); e != nil {
		this.logFunc(LogError, "ERROR parsing %s: %s\n", res.Request.URL.String(), e.Error())
	} else {
		doc = goquery.NewDocumentFromNode(node)
		doc.Url = res.Request.URL
	}

	// Visit the document (with nil goquery doc if failed to load)
	if this.visitor != nil {
		if harvested, doLinks = this.visitor(res, doc); doLinks && doc != nil {
			// Links were not processed by the visitor, so process links
			harvested = this.processLinks(doc)
		}
	} else {
		this.logFunc(LogInfo, "missing visitor function: %s\n", res.Request.URL.String())
	}

	return harvested
}
开发者ID:seacoastboy,项目名称:gocrawl,代码行数:26,代码来源:worker.go


示例4: HttpGetHtmlDoc

func (md *MangaDownloader) HttpGetHtmlDoc(u *url.URL) (*goquery.Document, error) {
	node, err := md.HttpGetHtml(u)
	if err != nil {
		return nil, err
	}
	return goquery.NewDocumentFromNode(node), err
}
开发者ID:pierrre,项目名称:mangadownloader,代码行数:7,代码来源:mangadownloader.go


示例5: parseChapter

func parseChapter() {
	defer chapterWg.Done()

	for chapter := range chaptersIn {
		filename := chapter.path
		b, err := ioutil.ReadFile(filename)

		var m map[string]*json.RawMessage
		err = json.Unmarshal(b, &m)
		if err != nil {
			panic(err)
		}

		var s string
		json.Unmarshal(*m["content"], &s)

		node, err := html.Parse(strings.NewReader(s))
		if err != nil {
			panic(err)
		}

		doc := gq.NewDocumentFromNode(node)
		verses := doc.Find(".verse")
		verses.Each(func(i int, s *gq.Selection) {
			chaptersOut <- Verse{book: chapter.book, chapter: chapter.chapter, html: s}
		})
	}
}
开发者ID:spiffytech,项目名称:bible_fixer,代码行数:28,代码来源:bible_fixer.go


示例6: clean_display_none

//style="display:none"
func clean_display_none(node *html.Node) *html.Node {
	doc := gq.NewDocumentFromNode(node)
	doc.Find("div").Each(func(i int, s *gq.Selection) {
		if style_display_none(s.AttrOr("style", "")) {
			s.Remove()
		}
	})
	return node
}
开发者ID:heartszhang,项目名称:haidian,代码行数:10,代码来源:html.go


示例7: parseHtml

func parseHtml(h string) (*goquery.Document, error) {
	node, err := html.Parse(strings.NewReader(h))
	if err != nil {
		log.Println("parsing failed - %s %s", err.Error())
		return nil, err
	}
	doc := goquery.NewDocumentFromNode(node)
	return doc, nil
}
开发者ID:zackb,项目名称:code,代码行数:9,代码来源:grab.go


示例8: clean_iframe_none

func clean_iframe_none(node *html.Node) *html.Node {
	gq.NewDocumentFromNode(node).Find("iframe").Each(func(i int, s *gq.Selection) {
		if style := s.AttrOr("style", ""); style_display_none(style) || style_dim_is_small(style) {
			s.Remove()
			return
		}
	})

	return node
}
开发者ID:heartszhang,项目名称:haidian,代码行数:10,代码来源:html.go


示例9: flattenTable

func flattenTable(table *html.Node) (selections []*goquery.Selection) {
	doc := goquery.NewDocumentFromNode(table)
	selections = make([]*goquery.Selection, 0)
	doc.Find("tr").Each(func(i int, row *goquery.Selection) {
		row.RemoveFiltered("tr")
		if row.Text() != "" {
			selections = append(selections, row)
		}
	})
	return
}
开发者ID:sellweek,项目名称:vlaky,代码行数:11,代码来源:parse.go


示例10: loadDoc

func loadDoc(page string) *goquery.Document {
	if f, e := os.Open(fmt.Sprintf("testdata/%s", page)); e != nil {
		panic(e.Error())
	} else {
		defer f.Close()
		if node, e := html.Parse(f); e != nil {
			panic(e.Error())
		} else {
			return goquery.NewDocumentFromNode(node)
		}
	}
	return nil
}
开发者ID:sejoharp,项目名称:kickerstats,代码行数:13,代码来源:gameParserSpec.go


示例11: Print

func Print(dao *models.Dao, page models.PageHtml, c *elastigo.Conn) {

	doc, err := html.Parse(strings.NewReader(page.Html))
	if err != nil {
		log.Fatal(err)
	}
	document := goquery.NewDocumentFromNode(doc)
	if document == nil {
	}

	StartParser(dao, document, c)

	fmt.Println("url:%s", page.Url)
}
开发者ID:herotl2005,项目名称:go-parser,代码行数:14,代码来源:parser.go


示例12: generateDoc

func generateDoc(htmlStr string, articleUrl string) *goquery.Document {
	node, _ := html.Parse(strings.NewReader(htmlStr))
	doc := goquery.NewDocumentFromNode(node)

	aUrl, err := url.Parse(articleUrl)
	if err == nil {
		doc.Url = aUrl
	} else {

		log.Println(err)
	}

	return doc
}
开发者ID:frankMilde,项目名称:rol,代码行数:14,代码来源:html2tex.go


示例13: LoadDoc

func LoadDoc(page string) *goquery.Document {
	base, _ := os.Getwd()
	if file, e := os.Open(base + "/" + page); e != nil {
		panic(e.Error())
	} else {
		defer file.Close()
		if node, e := html.Parse(file); e != nil {
			panic(e.Error())
		} else {
			return goquery.NewDocumentFromNode(node)
		}
	}
	return nil
}
开发者ID:korroktheslavemaster,项目名称:jee,代码行数:14,代码来源:parser.go


示例14: ParseReleases

//parse the http resp from Townclient
func (g *Ghostparser) ParseReleases() error {
	log.Info("%s parsing %v", TAG, g.Url)

	resp, err := g.Gc.Get(g.Url)
	if err != nil {
		log.Error("%s %s", TAG, err.Error())
		return err
	}
	defer resp.Body.Close()

	respbody, err := html.Parse(resp.Body)
	doc := goquery.NewDocumentFromNode(respbody)

	var rel Release
	doc.Find("table").Each(func(a int, sa *goquery.Selection) {
		if a == 10 { //get the right table
			sa.Find("tr").Each(func(b int, sb *goquery.Selection) {
				sb.Find("td").Each(func(c int, sc *goquery.Selection) {
					if c == 2 {
						rel = Release{}
						g.getUrlAndTagAndName(&rel, sc)

						if rel.Name != "" {
							rel.Time = time.Now().Unix()
							rel.Checksum = g.encodeName(rel.Url)
							rel.checkQual()
							if rel.Name != "" {
								rel.Hits = 0
								rel.Rating = 0
								g.downloadImage(rel.Url, rel.Checksum)
								g.addRelease(rel)
							}
						}
					}
				})
			})
		}
		if g.Count == 0 { //get page count
			if a == 51 {
				sa.Find("a").Each(func(d int, sd *goquery.Selection) {
					if d == 3 {
						g.Count, err = strconv.Atoi(sd.Text())
					}
				})
			}
		}
	})

	return nil
}
开发者ID:Bootz,项目名称:nzbcrawler,代码行数:51,代码来源:g_parser.go


示例15: RunCodeTests

func RunCodeTests(tests ConversionTests, fn func(*goquery.Document, string)) error {
	for _, test := range tests {

		node, _ := html.Parse(strings.NewReader(test.In))
		doc := goquery.NewDocumentFromNode(node)

		fn(doc, "")
		got := doc.Text()

		if err := MustBeEqual(got, test.Want); err != nil {
			return err
		}
	}
	return nil
}
开发者ID:frankMilde,项目名称:rol,代码行数:15,代码来源:testutils.go


示例16: loadPage

func loadPage(t *testing.T, page string) *goquery.Document {
	var f *os.File
	var e error

	if f, e = os.Open(fmt.Sprintf("./test_data/%s", page)); e != nil {
		t.Fatal(e)
	}
	defer f.Close()

	var node *html.Node
	if node, e = html.Parse(f); e != nil {
		t.Fatal(e)
	}
	return goquery.NewDocumentFromNode(node)
}
开发者ID:lucmichalski,项目名称:crawler,代码行数:15,代码来源:crawler_test.go


示例17: NewDocument

func NewDocument(url string) (d *goquery.Document, e error) {
	client := newHttpClient()
	res, e := client.Get(url)
	if e != nil {
		return
	}
	defer res.Body.Close()

	// Parse the HTML into nodes
	root, e := html.Parse(res.Body)
	if e != nil {
		return
	}

	// Create and fill the document
	d = goquery.NewDocumentFromNode(root)
	return
}
开发者ID:koyachi,项目名称:go-boomkat,代码行数:18,代码来源:goquerywrapper.go


示例18: getResult

func getResult(rollno int, ch1 chan Student, ch2 chan bool) {
	if resp, err := http.PostForm("http://jee.iitd.ac.in/resultstatus.php",
		url.Values{"regno": {strconv.Itoa(rollno)}, "submit": {"Submit"}}); err == nil {
		defer resp.Body.Close()
		body, _ := ioutil.ReadAll(resp.Body)
		if node, e := html.Parse(strings.NewReader(string(body))); e != nil {
			fmt.Println(e)
			ch1 <- Student{}
			ch2 <- false
		} else {
			a, b := GetStudent(goquery.NewDocumentFromNode(node), rollno)
			ch1 <- a
			ch2 <- b
		}
	}
	ch1 <- Student{}
	ch2 <- false
}
开发者ID:korroktheslavemaster,项目名称:jee,代码行数:18,代码来源:query.go


示例19: addInlineArticleImageHTML

func (a *Article) addInlineArticleImageHTML(title string) {
	if a.Img == nil {
		return
	}

	if a.TopNode == nil {
		a.TopNode = goquery.NewDocumentFromNode(&html.Node{
			Type:     html.ElementNode,
			DataAtom: atom.Span,
			Data:     "span",
		}).Selection
	}

	a.TopNode.PrependHtml(fmt.Sprintf(imgHeader,
		html.EscapeString(a.URL),
		html.EscapeString(title),
		html.EscapeString(a.Img.Src)))
}
开发者ID:oudommeas,项目名称:swan,代码行数:18,代码来源:article.go


示例20: getCCache

func (a *Article) getCCache(n *html.Node) *contentCache {
	cc, ok := a.cCache[n]
	if !ok {
		s := goquery.NewDocumentFromNode(n).Selection
		cc = &contentCache{
			text: strings.TrimSpace(s.Text()),
			s:    s,
		}

		ws := splitText(cc.text)
		cc.wordCount = uint(len(ws))
		cc.stopwords = stopwordCountWs(a.Meta.Lang, ws)
		cc.highLinkDensity = highLinkDensity(cc)
		a.cCache[n] = cc
	}

	return cc
}
开发者ID:oudommeas,项目名称:swan,代码行数:18,代码来源:article.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang goquery.NewDocumentFromReader函数代码示例发布时间:2022-05-28
下一篇:
Golang goquery.NewDocument函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap