本文整理匯總了Golang中github.com/zhangxiaoyang/goDataAccess/spider/common.Yield類的典型用法代碼示例。如果您正苦於以下問題:Golang Yield類的具體用法?Golang Yield怎麽用?Golang Yield使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Yield類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Process
func (this *LazyProcesser) Process(resp *common.Response, y *common.Yield) {
y.AddItem(func() *common.Item {
item := common.NewItem()
item.Set("html", resp.Body)
return item
}())
}
示例2: Process
func (this *MyProcesser) Process(resp *common.Response, y *common.Yield) {
m := regexp.MustCompile(`(?s)<div id="ua_string">.*?</span>(.*?)</div>`).FindAllStringSubmatch(resp.Body, -1)
for _, v := range m {
item := common.NewItem()
item.Set("user-agent", v[1])
y.AddItem(item)
}
}
示例3: processTitle
func (this *MyProcesser) processTitle(resp *common.Response, y *common.Yield) {
m := regexp.MustCompile(`(?s)<div class="channel-item">.*?<h3><a href="(.*?)">(.*?)</a>`).FindAllStringSubmatch(resp.Body, -1)
for _, v := range m {
item := common.NewItem()
item.Set("url", v[1])
item.Set("title", v[2])
y.AddItem(item)
}
}
示例4: Process
func (this *MyProcesser) Process(resp *common.Response, y *common.Yield) {
y.AddItem(func() *common.Item {
item := common.NewItem()
item.Set("url", resp.Url)
item.Set("title", func() string {
m := regexp.MustCompile(`<title>(.*?)</title>`).FindStringSubmatch(resp.Body)
if len(m) > 0 {
return m[1]
}
return ""
}())
return item
}())
}
示例5: Process
func (this *MyProcesser) Process(resp *common.Response, y *common.Yield) {
items := extractor.NewExtractor().
SetScopeRule(`(?s)<dt class="basicInfo-item name">.*?</dd>`).
SetRules(map[string]string{
"key": `(?s)name">(.*?)</dt>`,
"value": `(?s)value">(.*?)</dd>`,
}).
SetTrimFunc(extractor.TrimHtmlTags).
Extract(resp)
for _, item := range items {
y.AddItem(item)
}
}
示例6: processItems
func (this *QuickEngineProcesser) processItems(resp *common.Response, y *common.Yield, rule _Rule) {
var TrimFunc extractor.TrimFunc
switch rule.ItemRule.TrimFunc {
case "trim_html_tags":
TrimFunc = extractor.TrimHtmlTags
case "trim_blank":
TrimFunc = extractor.TrimBlank
}
items := extractor.NewExtractor().
SetScopeRule(rule.ItemRule.ScopeRule).
SetRules(rule.ItemRule.KVRule).
SetTrimFunc(TrimFunc).
Extract(resp)
for _, item := range items {
y.AddItem(item)
}
}
示例7: Process
func (this *QuickEngineProcesser) Process(resp *common.Response, y *common.Yield) {
common.Try(func() {
for _, rule := range this.config.Rules {
if regexp.MustCompile(rule.UrlMatch).MatchString(resp.Url) {
if rule.Succ != "" && !strings.Contains(resp.Body, rule.Succ) {
log.Printf("cannot find succ string:%s", rule.Succ)
break
}
if rule.ItemRule.ScopeRule != "" {
this.processItems(resp, y, rule)
}
if rule.RequestRule.ScopeRule != "" {
this.processRequests(resp, y, rule)
}
y.SetMerge(rule.Merge)
break //Only use the first match
}
}
}, func(e interface{}) {
log.Printf("pannic %s\n", e)
})
}
示例8: processRequests
func (this *QuickEngineProcesser) processRequests(resp *common.Response, y *common.Yield, rule _Rule) {
var TrimFunc extractor.TrimFunc
switch rule.RequestRule.TrimFunc {
case "trim_html_tags":
TrimFunc = extractor.TrimHtmlTags
case "trim_blank":
TrimFunc = extractor.TrimBlank
}
items := extractor.NewExtractor().
SetScopeRule(rule.RequestRule.ScopeRule).
SetRules(rule.RequestRule.KVRule).
SetTrimFunc(TrimFunc).
Extract(resp)
for _, item := range items {
for _, url := range item.GetAll() {
if strings.HasPrefix(url, "http://") {
y.AddRequest(common.NewRequest(url))
} else {
y.AddRequest(common.NewRequest(rule.BaseUrl + url))
}
}
}
}
示例9: processNext
func (this *MyProcesser) processNext(resp *common.Response, y *common.Yield) {
m := regexp.MustCompile(`(?s)<span class="next">.*?<a href="(.*?)"`).FindStringSubmatch(resp.Body)
if len(m) > 0 {
y.AddRequest(common.NewRequest(this.baseUrl + m[1]))
}
}