本文整理匯總了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
}
示例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)
}
示例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
}
示例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
}
示例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}
})
}
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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)
}
示例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
}
示例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
}
示例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
}
示例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
}