Skip to content

Commit

Permalink
[update] 代理抓取时添加异常捕获
Browse files Browse the repository at this point in the history
  • Loading branch information
jhao104 committed Jan 18, 2018
1 parent a4c341d commit 275288d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
4 changes: 1 addition & 3 deletions Api/ProxyApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,10 @@
from flask import Flask, jsonify, request
from Util.GetConfig import GetConfig



from Manager.ProxyManager import ProxyManager

app = Flask(__name__)


api_list = {
'get': u'get an usable proxy',
# 'refresh': u'refresh proxy pool',
Expand Down Expand Up @@ -78,5 +75,6 @@ def run():
config = GetConfig()
app.run(host=config.host_ip, port=config.host_port)


if __name__ == '__main__':
run()
7 changes: 4 additions & 3 deletions ProxyGetter/getFreeProxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def freeProxySecond(proxy_number=100):
:return:
"""
url = "http://www.66ip.cn/mo.php?sxb=&tqsl={}&port=&export=&ktip=&sxa=&submit=%CC%E1++%C8%A1&textarea=".format(
proxy_number)
proxy_number)
request = WebRequest()
# html = request.get(url).content
# content为未解码,text为解码后的字符串
Expand Down Expand Up @@ -162,6 +162,7 @@ def freeProxySeventh():
for tr in proxy_list[1:]:
yield ':'.join(tr.xpath('./td/text()')[0:2])


if __name__ == '__main__':
gg = GetFreeProxy()
# for e in gg.freeProxyFirst():
Expand All @@ -171,12 +172,12 @@ def freeProxySeventh():
# print(e)
#
# for e in gg.freeProxyThird():
# print(e)
# print(e)

# for e in gg.freeProxyFourth():
# print(e)

#for e in gg.freeProxyFifth():
# for e in gg.freeProxyFifth():
# print(e)

# for e in gg.freeProxySixth():
Expand Down
4 changes: 2 additions & 2 deletions Run/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import sys
from multiprocessing import Process


sys.path.append('../')

from Api.ProxyApi import run as ProxyApiRun
Expand All @@ -38,5 +37,6 @@ def run():
for p in p_list:
p.join()


if __name__ == '__main__':
run()
run()
4 changes: 2 additions & 2 deletions Schedule/ProxyCheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def run(self):
proxy_item = self.db.pop()
while proxy_item:
proxy = proxy_item.get('proxy')
counter = proxy_item.get('value')
counter = proxy_item.get('value', 1)
if validUsefulProxy(proxy):
# 验证通过计数器加1
if counter and int(counter) < 1:
Expand All @@ -48,7 +48,7 @@ def run(self):
else:
self.log.info('ProxyCheck: {} validation fail'.format(proxy))
# 验证失败,计数器减1
if counter and int(counter) <= -FAIL_COUNT:
if counter and int(counter) <= FAIL_COUNT:
self.log.info('ProxyCheck: {} fail too many, delete!'.format(proxy))
self.db.delete(proxy)
else:
Expand Down

0 comments on commit 275288d

Please sign in to comment.