func NewSurfer(useCookie bool, paseTime time.Duration, proxy ...string) *Surfer {
	sf := surfer.New()
	if len(proxy) != 0 {
		sf.SetProxy(proxy[0])
	}

	return &Surfer{
		download: sf,
	}
}
import (
	"net/http"

	"github.com/henrylee2cn/pholcus/app/downloader/context"
	"github.com/henrylee2cn/pholcus/config"
	"github.com/henrylee2cn/surfer"
)

type Surfer struct {
	surf    surfer.Surfer
	phantom surfer.Surfer
}

var SurferDownloader = &Surfer{
	surf:    surfer.New(),
	phantom: surfer.NewPhantom(config.SURFER_PHANTOM.FULL_APP_NAME, config.SURFER_PHANTOM.FULL_TEMP_JS),
}

func (self *Surfer) Download(cReq *context.Request) *context.Response {
	cResp := context.NewResponse(nil)

	var resp *http.Response
	var err error

	if cReq.GetUsePhantomJS() {
		resp, err = self.phantom.Download(cReq)
	} else {
		resp, err = self.surf.Download(cReq)
	}
package downloader

import (
	"github.com/henrylee2cn/pholcus/app/downloader/context"
	"github.com/henrylee2cn/surfer"
)

type Surfer struct {
	download surfer.Surfer
}

var SurferDownloader = &Surfer{
	download: surfer.New(),
}

func (self *Surfer) Download(cReq *context.Request) *context.Response {
	cResp := context.NewResponse(nil)

	resp, err := self.download.Download(cReq)

	cResp.SetRequest(cReq)

	cResp.SetResponse(resp)

	cResp.SetError(err)

	return cResp
}
Exemple #4
0
package example

import (
	"github.com/henrylee2cn/surfer"
	"net/http"
)

var SurfDownloader = surfer.New()

func SurfDownload(req *Request) (*http.Response, error) {
	return SurfDownloader.Download(req)
}
func NewSurfer() *Surfer {
	return &Surfer{
		download: surfer.New(),
	}
}