当前位置: 首页>>代码示例>>Golang>>正文


Golang Page.AddTargetRequest方法代码示例

本文整理汇总了Golang中github.com/jixiuf/go_spider/core/common/page.Page.AddTargetRequest方法的典型用法代码示例。如果您正苦于以下问题:Golang Page.AddTargetRequest方法的具体用法?Golang Page.AddTargetRequest怎么用?Golang Page.AddTargetRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/jixiuf/go_spider/core/common/page.Page的用法示例。


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

示例1: Process

// Parse html dom here and record the parse result that we want to crawl.
// Package simplejson (https://github.com/bitly/go-simplejson) is used to parse data of json.
func (this *MyPageProcesser) Process(p *page.Page) {
	if !p.IsSucc() {
		println(p.Errormsg())
		return
	}

	query := p.GetJson()
	status, err := query.GetPath("result", "status", "code").Int()
	if status != 0 || err != nil {
		log.Panicf("page is crawled error : errorinfo=%s : status=%d : startNewsId=%d", err.Error(), status, this.startNewsId)
	}
	num, err := query.GetPath("result", "pageStr", "pageSize").Int()
	if num == 0 || err != nil {
		// Add url of next crawl
		startIdstr := strconv.Itoa(this.startNewsId)
		p.AddTargetRequest("http://live.sina.com.cn/zt/api/l/get/finance/globalnews1/index.htm?format=json&id="+startIdstr+"&pagesize=10&dire=f", "json")
		return
	}

	var idint, nextid int
	var nextidstr string
	query = query.Get("result").Get("data")
	for i := 0; i < num; i++ {
		id, err := query.GetIndex(i).Get("id").String()
		if id == "" || err != nil {
			continue
		}
		idint, err = strconv.Atoi(id)
		if err != nil {
			continue
		}
		if idint <= this.startNewsId {
			break
		}
		if i == 0 {
			nextid = idint
			nextidstr = id
		}
		content, err := query.GetIndex(i).Get("content").String()
		if content == "" || err != nil {
			continue
		}
		time, err := query.GetIndex(i).Get("created_at").String()
		if err != nil {
			continue
		}

		p.AddField(id+"_id", id)
		p.AddField(id+"_content", content)
		p.AddField(id+"_time", time)
	}
	// Add url of next crawl
	this.startNewsId = nextid
	p.AddTargetRequest("http://live.sina.com.cn/zt/api/l/get/finance/globalnews1/index.htm?format=json&id="+nextidstr+"&pagesize=10&dire=f", "json")
	//println(p.GetTargetRequests())

}
开发者ID:jixiuf,项目名称:go_spider,代码行数:59,代码来源:main.go

示例2: Process

// Parse html dom here and record the parse result that we want to crawl.
// Package goquery (http://godoc.org/github.com/PuerkitoBio/goquery) is used to parse html.
func (this *MyPageProcesser) Process(p *page.Page) {
	if !p.IsSucc() {
		println(p.Errormsg())
		return
	}

	html := p.GetBodyStr()
	newUrls := urlutil.GetAllUrlIn(p.GetRequest().GetUrl(), html)
	for _, newUrl := range newUrls {
		newUrl = strings.Replace(newUrl, "//weibo.com/", "//tw.weibo.com/", -1)
		p.AddTargetRequest(newUrl, "html")
	}

	mailAddrList := mailaddrutil.GetAllMailAddrIn(html)
	for _, mailAddr := range mailAddrList {
		if _, ok := this.mailAddrMap[mailAddr]; !ok {
			this.mailAddrMap[mailAddr] = true
			this.mailLogger.WriteString(mailAddr + "\n")
			this.MailHandle.Push(mailAddr)
		}
	}
}
开发者ID:jixiuf,项目名称:mailaddrpasergo,代码行数:24,代码来源:main.go


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