本文整理匯總了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...)
}