Example #1
0
File: spider.go Project: kekek/test
// 指定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)
}
Example #2
0
File: spider.go Project: kekek/test
// 输出文本结果
// 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)
	}
}
Example #3
0
File: spider.go Project: kekek/test
// 输出文件结果
func (self *Spider) FileOutput(resp *context.Response, name ...string) {
	resp.AddFile(name...)
}