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


Golang Request.GetResponceType方法代码示例

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


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

示例1: downloadJson

func (this *HttpDownloader) downloadJson(p *page.Page, req *request.Request) *page.Page {
	var err error
	p, destbody := this.downloadFile(p, req)
	if !p.IsSucc() {
		return p
	}

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

	var r *simplejson.Json
	if r, err = simplejson.NewJson(body); err != nil {
		mlog.LogInst().LogError(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:CrocdileChan,项目名称:go_spider,代码行数:27,代码来源:downloader_http.go

示例2: Download

func (this *HttpDownloader) Download(req *request.Request) *page.Page {
	var mtype string
	mtype = req.GetResponceType()
	switch mtype {
	case "html":
		return this.downloadHtml(req)
	case "json":
		return this.downloadJson(req)
	default:
		mlog.LogInst().LogError("error request type:" + mtype)
		return nil
	}
}
开发者ID:w3hacker,项目名称:go_spider,代码行数:13,代码来源:downloader_http.go

示例3: Download

func (this *HttpDownloader) Download(req *request.Request) *page.Page {
	var mtype string
	var p = page.NewPage(req)
	mtype = req.GetResponceType()
	switch mtype {
	case "html":
		return this.downloadHtml(p, req)
	case "json":
		fallthrough
	case "jsonp":
		return this.downloadJson(p, req)
	case "text":
		return this.downloadText(p, req)
	default:
		mlog.LogInst().LogError("error request type:" + mtype)
	}
	return p
}
开发者ID:CrocdileChan,项目名称:go_spider,代码行数:18,代码来源:downloader_http.go


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