Coder Social home page Coder Social logo

proxypool's Introduction

Travis Status for henson/MusicDownloader Go Report Card

Golang实现的IP代理池

采集免费的代理资源为爬虫提供有效的代理

1、代理池设计

  代理池由四部分组成:

  • Getter:

  代理获取接口,目前有9个免费代理源,每调用一次就会抓取这些网站最新的100个代理放入Channel,可自行添加额外的代理获取接口;

  • Channel:

  临时存放采集来的代理,通过访问稳定的网站去验证代理的有效性,有效则存入数据库;

  • Schedule:

  用定时的计划任务去检测数据库中代理IP的可用性,删除不可用的代理。同时也会主动通过Getter去获取最新代理;

  • Api:

  代理池的访问接口,提供get接口输出JSON,方便爬虫直接使用。

2、代码实现

  • Api:

  api接口相关代码,提供get接口,输出JSON;

  • Storage:

  数据库相关代码,数据库采用Mongo;

  • Getter:

  代理获取接口,目前抓取这九个网站的免费代理,当然也支持自己扩展代理接口;

  1. 快代理
  2. 代理66
  3. IP181
  4. 有代理
  5. 西刺代理
  6. guobanjia
  7. 讯代理
  8. 无忧代理
  9. Proxylist+
  • Schedule:

  定时任务,目前在main.go中以轮询方式实现,后期会改进;

  • Util:

  存放一些公共的模块、方法或函数,包含Config:读取配置文件config.json;

  • 其他文件:

  配置文件:config.json,数据库配置和代理获取接口配置;

{
    "mongo": {
        "addr": "mongodb://127.0.0.1:27017/",
        "db": "temp",
        "table": "pool"
    },
    "host": ":8080"
}

3、安装及使用

因为有些代理网站使用了加密页面、混淆代码等反爬技术,要正确采集到代理数据得用到 PhantomJS ,必须提前先装好。

另外,本项目用到的依赖库有:

gopkg.in/mgo.v2
github.com/PuerkitoBio/goquery
github.com/parnurzeal/gorequest
github.com/nladuo/go-phantomjs-fetcher

下载本项目:

go get -u github.com/henson/ProxyPool

然后配置好相应的config.json并启动:

go build
./ProxyPool

随机输出可用的代理:

GET http://localhost:8080/v1/ip

HTTP

随机输出HTTPS代理:

GET http://localhost:8080/v1/https

HTTPS

4、感谢

感谢 J_hao104 提供思路。

proxypool's People

Contributors

henson avatar

Watchers

 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.