jhao104 пре 9 година
родитељ
комит
ed4a6e5b8d
9 измењених фајлова са 47 додато и 1 уклоњено
  1. 6 0
      Api/ProxyApi.py
  2. 1 0
      DB/DbClient.py
  3. 1 0
      DB/SsdbClient.py
  4. 2 0
      Manager/ProxyManager.py
  5. 32 0
      README.md
  6. 1 0
      Schedule/ProxyRefreshSchedule.py
  7. 1 0
      Util/GetConfig.py
  8. 1 0
      Util/utilClass.py
  9. 2 1
      Util/utilFunction.py

+ 6 - 0
Api/ProxyApi.py

@@ -1,4 +1,5 @@
 # -*- coding: utf-8 -*-
+# !/usr/bin/env python
 """
 -------------------------------------------------
    File Name:     ProxyApi.py  
@@ -29,26 +30,31 @@ api_list = {
 def index():
     return jsonify(api_list)
 
+
 @app.route('/get/')
 def get():
     proxy = ProxyManager().get()
     return proxy
 
+
 @app.route('/refresh/')
 def refresh():
     ProxyManager().refresh()
     return 'success'
 
+
 @app.route('/get_all/')
 def getAll():
     proxys = ProxyManager().getAll()
     return jsonify(proxys)
 
+
 @app.route('/delete/', methods=['GET'])
 def delete():
     proxy = request.args.get('proxy')
     ProxyManager().delete(proxy)
     return 'success'
 
+
 if __name__ == '__main__':
     app.run()

+ 1 - 0
DB/DbClient.py

@@ -1,4 +1,5 @@
 # -*- coding: utf-8 -*-
+# !/usr/bin/env python
 """
 -------------------------------------------------
    File Name:     DbClient.py  

+ 1 - 0
DB/SsdbClient.py

@@ -1,4 +1,5 @@
 # -*- coding: utf-8 -*-
+# !/usr/bin/env python
 """
 -------------------------------------------------
    File Name:     SsdbClient.py  

+ 2 - 0
Manager/ProxyManager.py

@@ -1,4 +1,5 @@
 # -*- coding: utf-8 -*-
+# !/usr/bin/env python
 """
 -------------------------------------------------
    File Name:     ProxyManager.py  
@@ -16,6 +17,7 @@ from DB.DbClient import DbClient
 from Util.GetConfig import GetConfig
 from ProxyGetter.GetFreeProxy import GetFreeProxy
 
+
 class ProxyManager(object):
     """
     ProxyManager

+ 32 - 0
README.md

@@ -49,17 +49,49 @@
   Python中高层次的数据结构,动态类型和动态绑定,使得它非常适合于快速应用开发,也适合于作为胶水语言连接已有的软件部件。用Python来搞这个代理IP池也很简单,代码分为6个模块:
 
 * Api:
+  api接口相关代码,目前api是由Flask实现,代码也非常简单。客户端请求传给Flask,Flask调用ProxyManager中的实现,包括`get/delete/refresh/get_all`;
 
 * DB:
+  数据库相关代码,目前数据库是采用SSDB。代码用工厂模式实现,方便日后扩展其他类型数据库;
 
 * Manager:
+  `get/delete/refresh/get_all`等接口的具体实现类,目前代理池只负责管理proxy,日后可能会有更多功能,比如代理和爬虫的绑定,代理和账号的绑定等等;
 
 * ProxyGetter:
+  代理获取的相关代码,目前抓取了[快代理](http://www.kuaidaili.com)、[代理66](http://www.66ip.cn/)、[有代理](http://www.youdaili.net/Daili/http/)、[西刺代理](http://api.xicidaili.com/free2016.txt)、[guobanjia](http://www.goubanjia.com/free/gngn/index.shtml)这个五个网站的免费代理,经测试这个5个网站每天更新的可用代理只有六七十个,当然也支持自己扩展代理接口;
 
 * Schedule:
+  定时任务相关代码,现在只是实现定时去刷新代码,并验证可用代理,采用多进程方式;
 
 * Util:
+  存放一些公共的模块方法或函数,包含`GetConfig`:读取配置文件config.ini的类,`ConfigParse`: 集成重写ConfigParser的类,使其对大小写敏感, `Singleton`:实现单例,`LazyProperty`:实现类属性惰性计算。等等;
 
 * 其他文件:
+  配置文件:Config.ini,数据库配置和代理获取接口配置,可以在GetFreeProxy中添加新的代理获取方法,并在Config.ini中注册即可使用;
 
+### 4、安装
+
+下载代码:
+```
+git clone git@github.com:jhao104/proxy_pool.git
+
+或者直接到https://github.com/jhao104/proxy_pool 下载zip文件
+```
+
+安装依赖:
+```
+pip install -r requirements.txt
+```
+
+启动:
+
+```
+需要分别启动定时任务和api
+
+到Schedule目录下:
+>>>python ProxyRefreshSchedule.py
+
+到Api目录下:
+>>>python ProxyApi.py
+```
 待更新,请耐心等待。。。。

+ 1 - 0
Schedule/ProxyRefreshSchedule.py

@@ -1,4 +1,5 @@
 # -*- coding: utf-8 -*-
+# !/usr/bin/env python
 """
 -------------------------------------------------
    File Name:     ProxyRefreshSchedule.py  

+ 1 - 0
Util/GetConfig.py

@@ -1,4 +1,5 @@
 # -*- coding: utf-8 -*-
+# !/usr/bin/env python
 """
 -------------------------------------------------
    File Name:     GetConfig.py  

+ 1 - 0
Util/utilClass.py

@@ -1,4 +1,5 @@
 # -*- coding: utf-8 -*-
+# !/usr/bin/env python
 """
 -------------------------------------------------
    File Name:     utilClass.py  

+ 2 - 1
Util/utilFunction.py

@@ -1,4 +1,5 @@
 # -*- coding: utf-8 -*-
+# !/usr/bin/env python
 """
 -------------------------------------------------
    File Name:     utilFunction.py  
@@ -34,6 +35,7 @@ def verifyProxy(proxy):
     verify_regex = r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d{1,4}"
     return True if re.findall(verify_regex, proxy) else False
 
+
 def getHtmlTree(url, **kwargs):
     """
     获取html树
@@ -45,4 +47,3 @@ def getHtmlTree(url, **kwargs):
     from lxml import etree
     html = requests.get(url=url).content
     return etree.HTML(html)
-