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


Golang context.Response类代码示例

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


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

示例1: commonPrase

func (b baiduNews) commonPrase(resp *context.Response) (infoStr string) {
	body := resp.GetDom().Find("body")

	var info *goquery.Selection

	if h1s := body.Find("h1"); len(h1s.Nodes) != 0 {
		for i := 0; i < len(h1s.Nodes); i++ {
			info = b.findP(h1s.Eq(i))
		}
	} else if h2s := body.Find("h2"); len(h2s.Nodes) != 0 {
		for i := 0; i < len(h2s.Nodes); i++ {
			info = b.findP(h2s.Eq(i))
		}
	} else if h3s := body.Find("h3"); len(h3s.Nodes) != 0 {
		for i := 0; i < len(h3s.Nodes); i++ {
			info = b.findP(h3s.Eq(i))
		}
	} else {
		info = body.Find("body")
	}
	// 去除标签
	// info.RemoveFiltered("script")
	// info.RemoveFiltered("style")
	infoStr, _ = info.Html()

	// 清洗HTML
	infoStr = CleanHtml(infoStr, 5)
	return
}
开发者ID:timesking,项目名称:spider_lib,代码行数:29,代码来源:baidunews.go

示例2: Parse

// 指定ruleName时,调用相应ParseFunc()解析响应流
// 未指定ruleName时或ruleName为空时,调用Root()
func (self *Spider) Parse(resp *context.Response, ruleName ...string) {
	if len(ruleName) == 0 || ruleName[0] == "" {
		if resp != nil {
			resp.SetRuleName("")
		}
		self.RuleTree.Root(self, resp)
		return
	}

	resp.SetRuleName(ruleName[0])
	self.GetRule(ruleName[0]).ParseFunc(self, resp)
}
开发者ID:husttaowen,项目名称:pholcus,代码行数:14,代码来源:spider.go

示例3: NewContext

func NewContext(sp *Spider, resp *context.Response) *Context {
	if resp == nil {
		return &Context{
			Spider:   sp,
			Response: resp,
		}
	}
	return &Context{
		Spider:   sp,
		Request:  resp.GetRequest(),
		Response: resp,
	}
}
开发者ID:BobbWu,项目名称:pholcus,代码行数:13,代码来源:context.go

示例4: Output

// 输出文本结果
// item允许的类型为map[int]interface{}或map[string]interface{}
func (self *Spider) Output(ruleName string, resp *context.Response, item interface{}) {
	resp.SetRuleName(ruleName)
	switch item2 := item.(type) {
	case map[int]interface{}:
		resp.AddItem(self.CreatItem(ruleName, item2))
	case map[string]interface{}:
		resp.AddItem(item2)
	}
}
开发者ID:husttaowen,项目名称:pholcus,代码行数:11,代码来源:spider.go

示例5: ExecParse

// 根据响应流运行指定解析Rule,仅用于crawl模块,Rule中请使用Parse()代替
func (self *Spider) ExecParse(resp *context.Response) {
	self.RuleTree.Trunk[resp.GetRuleName()].ParseFunc(self, resp)
}
开发者ID:rorovic,项目名称:pholcus,代码行数:4,代码来源:spider.go

示例6: Parse

// 调用指定Rule下解析函数ParseFunc(),解析响应流
func (self *Spider) Parse(ruleName string, resp *context.Response) {
	resp.SetRuleName(ruleName)
	self.ExecParse(resp)
}
开发者ID:rorovic,项目名称:pholcus,代码行数:5,代码来源:spider.go

示例7: FileOutput

// 输出文件结果
func (self *Spider) FileOutput(resp *context.Response, name ...string) {
	resp.AddFile(name...)
}
开发者ID:husttaowen,项目名称:pholcus,代码行数:4,代码来源:spider.go


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