بدون توضیح

jinghao_wb b9ccdfaada [update]文档 9 سال پیش
Api 0add262f4e [update] 停用Redis type SsdbClient支持redis 9 سال پیش
DB 0add262f4e [update] 停用Redis type SsdbClient支持redis 9 سال پیش
Manager 0add262f4e [update] 停用Redis type SsdbClient支持redis 9 سال پیش
ProxyGetter 551b35a1c3 更新第五个代理网站goubanjia.com的ip:port抓取方式,筛选页面中隐藏的混淆数字 9 سال پیش
Run c590e64e47 [update] 修改验证计数,放松验证 9 سال پیش
Schedule 0add262f4e [update] 停用Redis type SsdbClient支持redis 9 سال پیش
Test 20e39bfd1a [update]new function restName in LogHandler 9 سال پیش
Util 0add262f4e [update] 停用Redis type SsdbClient支持redis 9 سال پیش
doc f033b2d032 [update]更新文档 9 سال پیش
log 9e2fc04379 [update]修改Loghandler 9 سال پیش
.gitignore a3827cff50 [add] add WebRequest 9 سال پیش
.travis.yml af5b791504 [update] test 9 سال پیش
Config.ini 0add262f4e [update] 停用Redis type SsdbClient支持redis 9 سال پیش
Dockerfile 11d0580fc3 build docker image with Dockerfile, or run docker run -p 5000:5000 -d gladmo/proxy:latest 9 سال پیش
LICENSE 492b17df0f Create LICENSE 9 سال پیش
README.md b9ccdfaada [update]文档 9 سال پیش
__init__.py 47e6919835 [update] add Manager 9 سال پیش
_config.yml 3dfff5d7a1 Set theme jekyll-theme-time-machine 9 سال پیش
requirements.txt 78ab6ef362 [update] 修改ssdb module repo 9 سال پیش
test.py 23452cf915 [add] add test 9 سال پیش

README.md

爬虫IP代理池

Build Status Requirements Status Packagist GitHub contributors

介绍文档

下载安装

  • 下载源码:

    git clone git@github.com:jhao104/proxy_pool.git
    
    或者直接到https://github.com/jhao104/proxy_pool 下载zip文件
    
  • 安装依赖:

    pip install -r requirements.txt
    
  • 配置Config.ini:

    # Config.ini 为项目配置文件
    # 配置DB
    type = SSDB       # 如果使用SSDB或redis数据库,均配置为SSDB
    host = localhost  # db host
    port = 8888       # db port
    name = proxy      # 默认配置
    
    # 配置 ProxyGetter
    freeProxyFirst  = 1  # 这里是启动的抓取函数,可在ProxyGetter/getFreeProxy.py 扩展
    freeProxySecond = 1
    ....
    
    # 配置 HOST (api服务)
    ip = 127.0.0.1       # 监听ip,0.0.0.0开启外网访问
    port = 5010          # 监听端口
    # 上面配置启动后,代理api地址为 http://127.0.0.1:5010
    
    
  • 启动:

    # 如果你的依赖已经安全完成并且具备运行条件,可以直接在Run下运行main.py
    # 到Run目录下:
    >>>python main.py
    
    # 如果运行成功你应该看到有4个main.py进程
    
    # 你也可以分别运行他们,
    # 依次到Api下启动ProxyApi.py,Schedule下启动ProxyRefreshSchedule.py和ProxyValidSchedule.py即可.
    

使用

启动过几分钟后就能看到抓取到的代理IP,你可以直接到数据库中查看,推荐一个SSDB可视化工具

也可以通过api访问http://127.0.0.1:5010 查看。

  • Api
api method Description arg
/ GET api介绍 None
/get GET 随机获取一个代理 None
/get_all GET 获取所有代理 None
/get_status GET 查看代理数量 None
/delete GET 删除代理 proxy=host:ip
  • 爬虫使用

如果要在爬虫代码中使用的话, 可以将此api封装成函数直接使用,例如:

import requests

def get_proxy():
    return requests.get("http://127.0.0.1:5010/get/").content

def delete_proxy(proxy):
    requests.get("http://127.0.0.1:5010/delete/?proxy={}".format(proxy))

# your spider code

def getHtml():
    # ....
    retry_count = 5
    proxy = get_proxy()
    while retry_count > 0:
        try:
            html = requests.get('https://www.example.com', proxies={"http": "http://{}".format(proxy)})
            # 使用代理访问
            return html
        except Exception:
            retry_count -= 1
    # 出错5次, 删除代理池中代理
    delete_proxy(proxy)
    return None

问题反馈

任何问题欢迎在Issues 中反馈,如果没有账号可以去 我的博客中留言。

你的反馈会让此项目变得更加完美。

贡献代码

本项目仅作为基本的通用的代理池架构,不接收特有功能(当然,不限于特别好的idea)。

本项目依然不够完善,如果发现bug或有新的功能添加,请在Issues中提交bug(或新功能)描述,在确认后提交你的代码。

这里感谢以下contributor的无私奉献:

  @kangnwh| @bobobo80| @halleywj| @newlyedward| @wang-ye| @gladmo| @bernieyangmh| @PythonYXY| @zuijiawoniu