本文整理匯總了Golang中github.com/henrylee2cn/pholcus/app/downloader/context.Request.GetMethod方法的典型用法代碼示例。如果您正苦於以下問題:Golang Request.GetMethod方法的具體用法?Golang Request.GetMethod怎麽用?Golang Request.GetMethod使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/henrylee2cn/pholcus/app/downloader/context.Request
的用法示例。
在下文中一共展示了Request.GetMethod方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Push
// 添加請求到隊列
func (self *scheduler) Push(req *context.Request) {
// 初始化該蜘蛛的隊列
spiderId, ok := req.GetSpiderId()
if !ok {
return
}
self.RLock()
defer self.RUnlock()
if self.status == status.STOP {
return
}
// 當req不可重複時,有重複則返回
if !req.GetDuplicatable() && self.Deduplicate(req.GetUrl()+req.GetMethod()) {
return
}
// 初始化該蜘蛛下該優先級隊列
priority := req.GetPriority()
if !self.foundPriority(spiderId, priority) {
self.addPriority(spiderId, priority)
}
defer func() {
recover()
}()
// 添加請求到隊列
self.queue[spiderId][priority] = append(self.queue[spiderId][priority], req)
}
示例2: Process
// core processer
func (self *crawler) Process(req *context.Request) {
defer func() {
if err := recover(); err != nil {
// do not affect other
scheduler.Sdl.DelDeduplication(req.GetUrl() + req.GetMethod())
// 統計失敗數
cache.PageFailCount()
// 提示錯誤
logs.Log.Error(" * Fail [process panic]: %v", err)
}
}()
// download page
resp := self.Downloader.Download(req)
// if fail do not need process
if resp.GetError() != nil {
// 刪除該請求的去重樣本
scheduler.Sdl.DelDeduplication(req.GetUrl() + req.GetMethod())
// 統計失敗數
cache.PageFailCount()
// 提示錯誤
logs.Log.Error(" * Fail [download]: %v", resp.GetError())
return
}
// 過程處理,提煉數據
spider.NewContext(self.Spider, resp).Parse(resp.GetRuleName())
// 統計成功頁數
cache.PageSuccCount()
// 提示抓取成功
logs.Log.Informational(" * Success: %v", req.GetUrl())
// 該條請求文本結果存入pipeline
for _, data := range resp.GetItems() {
self.Pipeline.CollectData(
resp.GetRuleName(), //DataCell.RuleName
data, //DataCell.Data
resp.GetUrl(), //DataCell.Url
resp.GetReferer(), //DataCell.ParentUrl
time.Now().Format("2006-01-02 15:04:05"),
)
}
// 該條請求文件結果存入pipeline
for _, img := range resp.GetFiles() {
self.Pipeline.CollectFile(
resp.GetRuleName(),
img["Name"].(string),
img["Body"].(io.ReadCloser),
)
}
}
示例3: Download
func (self *Surfer) Download(cReq *context.Request) *context.Response {
cResp := context.NewResponse(nil)
resp, err := self.download.Download(cReq.GetMethod(), cReq.GetUrl(), cReq.GetReferer(), cReq.GetPostData(), cReq.GetHeader(), cReq.GetCookies())
cResp.SetRequest(cReq)
cResp.SetResponse(resp)
cResp.SetError(err)
return cResp
}
示例4: Push
// 添加請求到隊列
func (self *scheduler) Push(req *context.Request) {
self.pushMutex.Lock()
defer self.pushMutex.Unlock()
if self.status == status.STOP {
return
}
// 當req不可重複時,有重複則返回
if !req.GetDuplicatable() && self.Deduplicate(req.GetUrl()+req.GetMethod()) {
return
}
self.SrcManage.Push(req)
}
示例5: Process
// core processer
func (self *crawler) Process(req *context.Request) {
defer func() {
if err := recover(); err != nil { // do not affect other
logs.Log.Error(" * Process panic: %v", err)
}
}()
// logs.Log.Debug("**************斷點 1 ***********")
// download page
resp := self.Downloader.Download(req)
// logs.Log.Debug("**************斷點 2 ***********")
// if fail do not need process
if resp.GetError() != nil {
// 取消該請求的去重樣本
scheduler.Sdl.DelDeduplication(req.GetUrl() + req.GetMethod())
logs.Log.Error(" * %v", resp.GetError())
// 統計下載失敗的頁數
cache.PageFailCount()
return
}
// logs.Log.Debug("**************斷點 3 ***********")
// 過程處理,提煉數據
self.Spider.ExecParse(resp)
// logs.Log.Debug("**************斷點 5 ***********")
// 該條請求文本結果存入pipeline
for _, data := range resp.GetItems() {
self.Pipeline.CollectData(
resp.GetRuleName(), //DataCell.RuleName
data, //DataCell.Data
resp.GetUrl(), //DataCell.Url
resp.GetReferer(), //DataCell.ParentUrl
time.Now().Format("2006-01-02 15:04:05"),
)
}
// 該條請求文件結果存入pipeline
for _, img := range resp.GetFiles() {
self.Pipeline.CollectFile(
resp.GetRuleName(),
img["Name"].(string),
img["Body"].(io.ReadCloser),
)
}
// logs.Log.Debug("**************斷點 end ***********")
}
示例6: Download
func (self *Surfer) Download(cReq *context.Request) *context.Response {
cResp := context.NewResponse(nil)
resp, err := self.download.Download(cReq.GetMethod(), cReq.GetUrl(), cReq.GetReferer(), cReq.GetPostData(), cReq.GetHeader(), cReq.GetCookies())
cResp.SetRequest(cReq)
cResp.SetResponse(resp)
if err != nil {
logs.Log.Error(" * %v", err)
// cResp.SetStatus(false, err.Error())
// return cResp
}
cResp.SetStatus(true, "")
return cResp
}
示例7: Push
// 添加請求到隊列
func (self *scheduler) Push(req *context.Request) {
pushMutex.Lock()
defer func() {
pushMutex.Unlock()
}()
if self.status == status.STOP {
return
}
// 有重複則返回
if self.Compare(req.GetUrl() + req.GetMethod()) {
return
}
// 留作未來分發請求用
// if pholcus.Self.GetRunMode() == config.SERVER || req.CanOutsource() {
// return
// }
self.SrcManage.Push(req)
}
示例8: makeUnique
func makeUnique(req *context.Request) string {
return util.MakeUnique(req.GetUrl() + req.GetMethod())
}