Example #1
0
func (self *Surfer) Download(cReq *context.Request) *context.Response {
	cResp := context.NewResponse(nil)

	resp, err := self.download.Download(cReq.GetMethod(), cReq.GetUrl(), cReq.GetReferer(), cReq.GetPostData(), cReq.GetHeader(), cReq.GetCookies())

	cResp.SetRequest(cReq)

	cResp.SetResponse(resp)

	cResp.SetError(err)

	return cResp
}
Example #2
0
func (self *Surfer) Download(cReq *context.Request) *context.Response {
	cResp := context.NewResponse(nil)

	resp, err := self.download.Download(cReq.GetMethod(), cReq.GetUrl(), cReq.GetReferer(), cReq.GetPostData(), cReq.GetHeader(), cReq.GetCookies())

	cResp.SetRequest(cReq)

	cResp.SetResponse(resp)

	if err != nil {
		logs.Log.Error(" *     %v", err)
		// cResp.SetStatus(false, err.Error())
		// return cResp
	}

	cResp.SetStatus(true, "")
	return cResp
}
Example #3
0
// 生成并添加请求至队列。
// Request.Url与Request.Rule必须设置。
// Request.Spider无需手动设置(由系统自动设置)。
// Request.EnableCookie在Spider字段中统一设置,规则请求中指定的无效。
// 以下字段有默认值,可不设置:
// Request.Method默认为GET方法;
// Request.DialTimeout默认为常量context.DefaultDialTimeout,小于0时不限制等待响应时长;
// Request.ConnTimeout默认为常量context.DefaultConnTimeout,小于0时不限制下载超时;
// Request.TryTimes默认为常量context.DefaultTryTimes,小于0时不限制失败重载次数;
// Request.RedirectTimes默认不限制重定向次数,小于0时可禁止重定向跳转;
// Request.RetryPause默认为常量context.DefaultRetryPause;
// Request.DownloaderID指定下载器ID,0为默认的Surf高并发下载器,功能完备,1为PhantomJS下载器,特点破防力强,速度慢,低并发。
// 默认自动补填Referer。
func (self *Context) AddQueue(req *context.Request) *Context {
	err := req.
		SetSpiderName(self.Spider.GetName()).
		SetSpiderId(self.Spider.GetId()).
		SetEnableCookie(self.Spider.GetEnableCookie()).
		Prepare()

	if err != nil {
		logs.Log.Error("%v", err)
		return self
	}

	if req.GetReferer() == "" && self.Response != nil {
		req.SetReferer(self.Response.GetUrl())
	}

	scheduler.Sdl.Push(req)
	return self
}