Giter Club home page Giter Club logo

surfer's Introduction

Surfer GitHub release report card github issues github closed issues GoDoc view Go大数据

Package surfer is a high level concurrency http client. It has surf and phantom download engines, highly simulated browser behavior, the function of analog login and so on.

简体中文

Features

  • Both surf and phantomjs engines are supported
  • Support random User-Agent
  • Support cache cookie
  • Support http/https

Usage

package main

import (
    "github.com/andeya/surfer"
    "io/ioutil"
    "log"
)

func main() {
    // Use surf engine
    resp, err := surfer.Download(&surfer.Request{
        Url: "http://github.com/andeya/surfer",
    })
    if err != nil {
        log.Fatal(err)
    }
    b, err := ioutil.ReadAll(resp.Body)
    log.Println(string(b), err)

    // Use phantomjs engine
    surfer.SetPhantomJsFilePath("Path to phantomjs.exe")
    resp, err = surfer.Download(&surfer.Request{
        Url:          "http://github.com/andeya",
        DownloaderID: 1,
    })
    if err != nil {
        log.Fatal(err)
    }
    b, err = ioutil.ReadAll(resp.Body)
    log.Println(string(b), err)

    resp.Body.Close()
    surfer.DestroyJsFiles()
}

Full example

License

Surfer is under Apache v2 License. See the LICENSE file for the full license text.

surfer's People

Contributors

andeya avatar liguoqinjim avatar wzshiming avatar yangwenmai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

surfer's Issues

网页中的js被设置了4s后才运行

大侠,surfer非常好,非常有用
但也遇到一个问题:
网页中的js通过setTimeout设置了4s后才运行,请问如何让停止4s以自动运行网页里面的js?

设置EnableCookie 并不能在登陆后继续使用cookie

if !r.EnableCookie {
		commonUserAgentIndex = rand.Intn(len(UserAgents["common"]))
		r.Header.Set("User-Agent", UserAgents["common"][commonUserAgentIndex])
	} else if len(r.Header["User-Agent"]) == 0 {
		r.Header.Set("User-Agent", UserAgents["common"][commonUserAgentIndex])
	}

回写请求时:
// 回写Request内容

func (r *Request) writeback(resp *http.Response) *http.Response {
	if resp == nil {
		resp = new(http.Response)
		resp.Request = new(http.Request)
	} else if resp.Request == nil {
		resp.Request = new(http.Request)
	}

	resp.Request.Method = r.Method
	resp.Request.Header = r.Header
	log.Printf("resp.Header: %v,  req.Header:%v", resp.Request.Header, r.Header)
	resp.Request.Host = r.url.Host

	// reset url
	r.url = nil

	return resp
}

输出结果:
2017/04/03 17:13:54 resp.Header: map[User-Agent:[Mozilla/5.0 (Windows NT 6.3; x64; rv:31.0) Gecko/20100101 Firefox/31]], req.Header:map[User-Agent:[Mozilla/5.0 (Windows NT 6.3; x64; rv:31.0) Gecko/20100101 Firefox/31]]

只有User-Agent。再发请求时Cookie为空

非常消耗内存 我用来做http 代理 2G内存直接吃完了 5个并发

package query

import (
	"bixin_old/common"
	"fmt"
	"github.com/henrylee2cn/surfer"
	"io/ioutil"
	"regexp"
	"strconv"
	"strings"
	"time"
)
var  s3 surfer.Surfer =  surfer.New()
func SogouRecord(domain string) (e error, i int,sr int) {
	unix := fmt.Sprintf("%d", time.Now().Unix())
	cUrl := `https://www.sogou.com/web?query=site%3A`+domain+`&_ast=`+unix+``

	resp, e := s3.Download(&surfer.Request{
		Url:cUrl,
	})
	if e != nil {
		return
	}
	defer  	resp.Body.Close()
	b, e := ioutil.ReadAll(resp.Body)
	if e != nil {
		return
	}

	data := common.RemoveHtmlTag( string(b))
	data = regexp.MustCompile(`[\r\n+|\n+|\t+|\s+]`).ReplaceAllString(data, "")
	s := regexp.MustCompile("找到约(.*?)条").FindStringSubmatch(data)
	if len(s) == 2 {
		sum := regexp.MustCompile(`[","| |\n+]`).ReplaceAllString(s[1], "")
		i, e = strconv.Atoi(sum)
		if e != nil {
			return
		}
	}
	e, data2 := _http.Get("https://www.sogou.com/sogourank?ur=http://" + domain)
	if e ==nil {
		data2 = strings.ReplaceAll(data2, "sogourank=", "")
		data2 = strings.ReplaceAll(data2, "\n", "")
		sr, e = strconv.Atoi(data2)
		if e != nil {
			return
		}
	}
	return
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.