本文整理汇总了Golang中github.com/PuerkitoBio/goquery.Document.Url方法的典型用法代码示例。如果您正苦于以下问题:Golang Document.Url方法的具体用法?Golang Document.Url怎么用?Golang Document.Url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/PuerkitoBio/goquery.Document
的用法示例。
在下文中一共展示了Document.Url方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例2: 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 bd, e := ioutil.ReadAll(res.Body); e != nil {
this.extender.Error(newCrawlError(e, CekReadBody, res.Request.URL))
this.logFunc(LogError, "ERROR reading body %s: %s", res.Request.URL.String(), e.Error())
} else {
if node, e := html.Parse(bytes.NewBuffer(bd)); e != nil {
this.extender.Error(newCrawlError(e, CekParseBody, res.Request.URL))
this.logFunc(LogError, "ERROR parsing %s: %s", res.Request.URL.String(), e.Error())
} else {
doc = goquery.NewDocumentFromNode(node)
doc.Url = res.Request.URL
}
// Re-assign the body so it can be consumed by the visitor function
res.Body = ioutil.NopCloser(bytes.NewBuffer(bd))
}
// Visit the document (with nil goquery doc if failed to load)
if harvested, doLinks = this.extender.Visit(res, doc); doLinks {
// Links were not processed by the visitor, so process links
if doc != nil {
harvested = this.processLinks(doc)
} else {
this.extender.Error(newCrawlErrorMessage("No goquery document to process links.", CekProcessLinks, res.Request.URL))
this.logFunc(LogError, "ERROR processing links %s", res.Request.URL.String())
}
}
// Notify that this URL has been visited
this.extender.Visited(res.Request.URL, harvested)
return harvested
}