當前位置: 首頁>>代碼示例>>Golang>>正文


Golang goquery.NewDocumentFromNode函數代碼示例

本文整理匯總了Golang中github.com/PuerkitoBio/goquery.NewDocumentFromNode函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewDocumentFromNode函數的具體用法?Golang NewDocumentFromNode怎麽用?Golang NewDocumentFromNode使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewDocumentFromNode函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的github.com/PuerkitoBio/goquery.NewDocumentFromNode函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。