forked from qiyeboy/IPProxyPool
-
Notifications
You must be signed in to change notification settings - Fork 1
/
IPProxys.py
45 lines (32 loc) · 985 Bytes
/
IPProxys.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#coding:utf-8
import BaseHTTPServer
import threading
import logging
import logging.config
from api.apiServer import WebRequestHandler
from config import API_PORT
from db.SQLiteHelper import SqliteHelper
from spider.ProxySpider import ProxySpider
import sys
reload(sys)
sys.setdefaultencoding('utf8')
logging.config.fileConfig('logging.conf')
class IPProxys(object):
def startApiServer(self):
'''
启动api服务器
:return:
'''
logging.info('Start server @ %s:%s' %('0.0.0.0',API_PORT))
server = BaseHTTPServer.HTTPServer(('0.0.0.0',API_PORT), WebRequestHandler)
server.serve_forever()
def startSpider(self):
logging.info('Start Spider')
spider = ProxySpider()
spider.run()
if __name__=="__main__":
proxys = IPProxys()
apiServer = threading.Thread(target=proxys.startApiServer)
spider = threading.Thread(target=proxys.startSpider)
apiServer.start()
spider.start()