• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang context.Request类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/henrylee2cn/pholcus/downloader/context.Request的典型用法代码示例。如果您正苦于以下问题:Golang Request类的具体用法?Golang Request怎么用?Golang Request使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: TryOutsource

func (self *Pholcus) TryOutsource(req *context.Request) bool {
	if self.IsOutsource() && req.TryOutsource() {
		self.Send(*req)
		return true
	}
	return false
}
开发者ID:houzhenggang,项目名称:pholcus,代码行数:7,代码来源:pholcus.go


示例2: downloadJson

func (self *HttpDownloader) downloadJson(p *context.Response, req *context.Request) *context.Response {
	var err error
	p, destbody := self.downloadFile(p, req)
	if !p.IsSucc() {
		return p
	}

	var body []byte
	body = []byte(destbody)
	mtype := req.GetRespType()
	if mtype == "jsonp" {
		tmpstr := util.JsonpToJson(destbody)
		body = []byte(tmpstr)
	}

	var r *simplejson.Json
	if r, err = simplejson.NewJson(body); err != nil {
		reporter.Log.Println(string(body) + "\t" + err.Error())
		p.SetStatus(true, err.Error())
		return p
	}

	// json result
	p.SetBodyStr(string(body)).SetJson(r).SetStatus(false, "")

	return p
}
开发者ID:houzhenggang,项目名称:pholcus,代码行数:27,代码来源:downloader_http.go


示例3: Push

func (self *scheduler) Push(req *context.Request) {
	is := self.Compare(req.GetUrl())
	// 有重复则返回
	if is {
		return
	}
	self.SrcManage.Push(req)
}
开发者ID:houzhenggang,项目名称:pholcus,代码行数:8,代码来源:scheduler.go


示例4: Push

func (self *scheduler) Push(req *context.Request) {
	if self.status == STOP {
		return
	}
	is := self.Compare(req.GetUrl() + req.GetMethod())
	// 有重复则返回
	if is {
		return
	}
	self.SrcManage.Push(req)
}
开发者ID:zydudu,项目名称:pholcus,代码行数:11,代码来源:scheduler.go


示例5: Push

func (self *SrcManage) Push(req *context.Request) {
	if spiderId, ok := req.GetSpiderId(); ok {
		priority := int(req.GetPriority())
		if priority > MAX_PRIORITY {
			priority = MAX_PRIORITY
		}

		for i, x := 0, priority+1-len(self.queue[spiderId]); i < x; i++ {
			self.queue[spiderId] = append(self.queue[spiderId], []*context.Request{})
		}

		self.queue[spiderId][priority] = append(self.queue[spiderId][priority], req)
	}
}
开发者ID:zydudu,项目名称:pholcus,代码行数:14,代码来源:src_manage.go


示例6: Download

func (self *HttpDownloader) Download(req *context.Request) *context.Response {
	var mtype string
	var p = context.NewResponse(req)
	mtype = req.GetRespType()
	switch mtype {
	case "html":
		return self.downloadHtml(p, req)
	case "json":
		fallthrough
	case "jsonp":
		return self.downloadJson(p, req)
	case "text":
		return self.downloadText(p, req)
	default:
		reporter.Log.Println("error request type:" + mtype)
	}
	return p
}
开发者ID:houzhenggang,项目名称:pholcus,代码行数:18,代码来源:downloader_http.go


示例7: connectByHttpProxy

// choose a proxy server to excute http GET/method to download
func connectByHttpProxy(p *context.Response, in_req *context.Request) (*http.Response, error) {
	request, _ := http.NewRequest("GET", in_req.GetUrl(), nil)
	proxy, err := url.Parse(in_req.GetProxyHost())
	if err != nil {
		return nil, err
	}
	client := &http.Client{
		Transport: &http.Transport{
			Proxy: http.ProxyURL(proxy),
		},
	}
	resp, err := client.Do(request)
	if err != nil {
		return nil, err
	}
	return resp, nil

}
开发者ID:houzhenggang,项目名称:pholcus,代码行数:19,代码来源:downloader_http.go


示例8: downloadFile

// Download file and change the charset of response charset.
func (self *HttpDownloader) downloadFile(p *context.Response, req *context.Request) (*context.Response, string) {
	var err error
	var urlstr string
	if urlstr = req.GetUrl(); len(urlstr) == 0 {
		reporter.Log.Println("url is empty")
		p.SetStatus(true, "url is empty")
		return p, ""
	}

	var resp *http.Response

	if proxystr := req.GetProxyHost(); len(proxystr) != 0 {
		//using http proxy
		//fmt.Print("HttpProxy Enter ",proxystr,"\n")
		resp, err = connectByHttpProxy(p, req)
	} else {
		//normal http download
		//fmt.Print("Http Normal Enter \n",proxystr,"\n")
		resp, err = connectByHttp(p, req)
	}

	if err != nil {
		return p, ""
	}

	//b, _ := ioutil.ReadAll(resp.Body)
	//fmt.Printf("Resp body %v \r\n", string(b))

	p.SetHeader(resp.Header)
	p.SetCookies(resp.Cookies())

	// get converter to utf-8
	bodyStr := self.changeCharsetEncodingAuto(resp.Header.Get("Content-Type"), resp.Body)
	//fmt.Printf("utf-8 body %v \r\n", bodyStr)
	defer resp.Body.Close()
	return p, bodyStr
}
开发者ID:houzhenggang,项目名称:pholcus,代码行数:38,代码来源:downloader_http.go


示例9: Download

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)

	if err != nil {
		cResp.SetStatus(true, err.Error())
		return cResp
	}

	// get converter to utf-8
	body := self.changeCharsetEncodingAuto(resp.Body, resp.Header.Get("Content-Type"))
	//fmt.Printf("utf-8 body %v \r\n", bodyStr)
	defer resp.Body.Close()
	cResp.SetText(body)
	cResp.SetStatus(false, "")
	return cResp
}
开发者ID:zydudu,项目名称:pholcus,代码行数:20,代码来源:downloader_surfer.go


示例10: connectByHttp

// choose http GET/method to download
func connectByHttp(p *context.Response, req *context.Request) (*http.Response, error) {
	client := &http.Client{
		CheckRedirect: req.GetRedirectFunc(),
	}

	httpreq, err := http.NewRequest(req.GetMethod(), req.GetUrl(), strings.NewReader(req.GetPostdata()))
	if header := req.GetHeader(); header != nil {
		httpreq.Header = req.GetHeader()
	}

	if cookies := req.GetCookies(); cookies != nil {
		for i := range cookies {
			httpreq.AddCookie(cookies[i])
		}
	}

	var resp *http.Response
	if resp, err = client.Do(httpreq); err != nil {
		if e, ok := err.(*url.Error); ok && e.Err != nil && e.Err.Error() == "normal" {
			//  normal
		} else {
			reporter.Log.Println(err.Error())
			p.SetStatus(true, err.Error())
			//fmt.Printf("client do error %v \r\n", err)
			return nil, err
		}
	}

	return resp, nil
}
开发者ID:houzhenggang,项目名称:pholcus,代码行数:31,代码来源:downloader_http.go


示例11: Push

func (self *SrcManage) Push(req *context.Request) {
	if spiderId, ok := req.GetSpiderId(); ok {
		self.queue[spiderId] = append(self.queue[spiderId], req)
	}
}
开发者ID:houzhenggang,项目名称:pholcus,代码行数:5,代码来源:src_manage.go



注:本文中的github.com/henrylee2cn/pholcus/downloader/context.Request类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang context.Response类代码示例发布时间:2022-05-28
下一篇:
Golang context.Response类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap