本文整理汇总了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
}
示例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)
}
示例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,
}
}
示例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)
}
}
示例5: ExecParse
// 根据响应流运行指定解析Rule,仅用于crawl模块,Rule中请使用Parse()代替
func (self *Spider) ExecParse(resp *context.Response) {
self.RuleTree.Trunk[resp.GetRuleName()].ParseFunc(self, resp)
}
示例6: Parse
// 调用指定Rule下解析函数ParseFunc(),解析响应流
func (self *Spider) Parse(ruleName string, resp *context.Response) {
resp.SetRuleName(ruleName)
self.ExecParse(resp)
}
示例7: FileOutput
// 输出文件结果
func (self *Spider) FileOutput(resp *context.Response, name ...string) {
resp.AddFile(name...)
}