Skip to content

diinvoke/proxy-pool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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()
}