Giter Club home page Giter Club logo

proxypool's Introduction

ProxyPool

Build Status
跨语言高性能IP代理池,Python实现。

注意:请运行程序前先更新一下抓取代理的函数。

运行环境

  • Python 3.5

    (请务必保证Python的版本在3.5以上,否则异步检验无法使用。)

  • Redis

    Redis官网并没有提供Windows的安装版,Windows用户可以点击此处下载一个我自己编译的二进制版本(3.2版本2.7MB,VS 2015编译)。

安装

① 直接使用

安装依赖

$ pip install -r requirements.txt

Windows用户如果无法安装lxml库请点击这里

打开代理池和API

$ cd proxypool

$ python3 run.py

② 安装使用

安装

$ cd proxypool

$ python setup.py install

打开代理池和API

$ proxypool_run

③ 使用二进制包

Windows 用户可以点击此处获取此程序的二进制包,直接运行。

使用API获取代理

访问http://127.0.0.1:5000/进入主页,如果显示'Welcome',证明成功启动。

pic

访问http://127.0.0.1:5000/get可以获取一个可用代理。

pic

访问http://127.0.0.1:5000/count可以获取代理池中可用代理的数量。

pic

也可以在程序代码中用相应的语言获取,例如:

import requests
from bs4 import BeautifulSoup
import lxml

def get_proxy():
    r = requests.get('http://127.0.0.1:5000/get')
    proxy = BeautifulSoup(r.text, "lxml").get_text()
    return proxy

各模块功能

  • proxyGetter.py

    爬虫模块

    • class proxypool.proxyGetter.FreeProxyGetter

      爬虫类,用于抓取代理源网站的代理,用户可复写和补充抓取规则。

  • schdule.py

    调度器模块

    • class proxypool.schdule.VaildityTester

      异步检测类,可以对给定的代理的可用性进行异步检测。

    • class proxypool.schdule.PoolAdder

      代理添加器,用来触发爬虫模块,对代理池内的代理进行补充,代理池代理数达到阈值时停止工作。

    • class proxypool.schdule.Schedule

      代理池启动类,运行RUN函数时,会创建两个进程,负责对代理池内容的增加和更新。

  • db.py

    Redis数据库连接模块

    • class proxypool.db.RedisClient

      数据库操作类,维持与Redis的连接和对数据库的增删查该,

  • error.py

    异常模块

    • class proxypool.error.ResourceDepletionError

      资源枯竭异常,如果从所有抓取网站都抓不到可用的代理资源,

      则抛出此异常。

    • class proxypool.error.PoolEmptyError

      代理池空异常,如果代理池长时间为空,则抛出此异常。

  • api.py

    API模块,启动一个Web服务器,对外提供代理的获取功能。

  • utils.py

    工具箱

  • setting.py

    设置

picture

proxypool's People

Contributors

liuslnlp avatar

Watchers

 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.