Skip to content

li-dong-chao/ProxyPool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ProxyPool

一个简单的代理池项目,主要用于从自动抓取网上的免费代理,对代理质量进行验证,并入库储存。

具体实现的功能点如下:

  • 通过Fetcher类实现对免费代理网站的爬取,包含一个简单的可插拔设计,方便扩展免费代理网站。
  • 通过Validator类实现对代理的活性验证。
  • 借用pydantic模块实现对代理类型的校验。
  • 使用fastapi进行功能封装,提供API接口方便直接调用。

部署方式

  • 下载源码到本地
git clone [email protected]:li-dong-chao/ProxyPool.git
  • 启动项目
cd ProxyPool
docker-compose up -d
  • 检查项目是否正常启动
docker logs --tail 100 proxypool

出现下面的内容,说明服务正常启动了

INFO:     Started server process [12]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
2023-03-27 12:33:32.914 | INFO     | app.fetcher.fetcher:get:27 - 开始抓取代理
2023-03-27 12:33:32.915 | INFO     | app.fetcher.fetcher:get:30 - <class 'app.fetcher.geonode.Geonode'> start
2023-03-27 12:33:38.874 | INFO     | app.fetcher.fetcher:get:30 - <class 'app.fetcher.ip66.IP66'> start
2023-03-27 12:34:26.006 | INFO     | app.fetcher.fetcher:get:30 - <class 'app.fetcher.ip89.IP89'> start

使用方式

本项目提供了4个API接口,方便在爬虫时直接调用。

  • 获取一个代理
    • 地址:http://:/get
    • 请求方式:get
    • 请求参数示例:
      • 无需参数
    • 返回结果示例:
      • http://127.0.0.1/7777 (有代理则返回该结果)
      • No proxy in pool. (代理池中无代理,返回该结果)
  • 删除一个代理
    • 地址:http://:/get
    • 请求方式:delete
    • 请求参数示例:
    • 返回结果示例:
      • OK
  • 查看所有代理数量
    • 地址:http://:/quantity/all
    • 请求方式:get
    • 请求参数示例:
      • 无需参数
    • 返回结果示例:
      • 100
  • 查看验证通过代理数量
    • 地址:http://:/quantity/valid
    • 请求方式:get
    • 请求参数示例:
      • 无需参数
    • 返回结果示例:
      • 100

扩展免费代理网站

app/fetcher目录下新增脚本 your_file_name.py, 该脚本中生成一个类,类目无限制,但是该类需要继承自app/fetcher/base.py中的BaseFetcher类, 并实现fetch方法,fetch方法即为爬虫代码,它通过yield返回一个代理类型(即app/schemas/proxy.py中的Proxy)。 脚本完成后,如果需要启动该方法,在app/fetcher/__init__.py中引入一下该类即可。

该项目是对以下两个开源项目的拙略模仿,仅作自己学习练手, 有类似在学习代理池搭建的同学,建议了解下这两个项目:

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published