Giter Club home page Giter Club logo

proxy-pool-1's Introduction

ip 代理池

下载安装

go get github.com/diinvoke/proxy-pool

安装依赖

go mod tidy

使用

demo

import (
	"github.com/diinvoke/proxy-pool"
	"github.com/diinvoke/proxy-pool/model"
)

func Random() *model.IP {
	rangeIp := proxypool.Range("https")
	
	// if need check
	// proxyUrl := proxyIp.Protocol + "://" + proxyIp.Address + ":" + proxyIp.Port
	// if !proxypool.Check(proxyUrl) {
		// return Random()
	// }
	
	return rangeIp
}

func Check(proxy string) bool {
	return proxypool.Check(proxy)
}

扩展抓取

spider包中编写抓取实现

import (
	"github.com/diinvoke/proxy-pool/storage"
)

type DemoSpider struct{}

func NewDemoSpider() Spider {
	return &DemoSpider{}
}

// implements Spider interface
var _ Spider = &DemoSpider{}

func (demo *DemoSpider) Do() error {
	// do something
}

init.go中添加或者替换实现

import "github.com/diinvoke/proxy-pool/spider"

spiders := []spider.ISpider{
	spider.NewIP181(store),
	spider.NewDemoSpider()
}

扩展存储

storage包中编写实现

import (
    "github.com/diinvoke/proxy-pool/model"
)

type DemoStorage struct{}
// implements Storage interface
var _ IStorage = &DemoStorage()

func NewDemoStorage() IStorage {
	return &DemoStorage{}
}

func (d *DemoStorage) Save(ip *model.IP) error {
	// do something
}

func (d *DemoStorage) Del(ip *model.IP) bool {
	// do something
}

func (d *DemoStorage) Random(protocol model.Protocol) (ip *model.IP, err error) {
	// do something
}

func (d *DemoStorage) Close() error {
	// do something
}

替换 proxy_pool.go 中 store 值

func init() {
	store = storage.NewDemoStorage()
	initProxyPool(store)

	go autoLoad()
}

proxy-pool-1's People

Contributors

diinvoke avatar

Watchers

James Cloos avatar  avatar

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.