forked from jhao104/proxy_pool
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jinghao_wb
committed
Sep 27, 2017
1 parent
c326ca1
commit e110207
Showing
4 changed files
with
79 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
------------------------------------------------- | ||
File Name: ProxyCheck | ||
Description : 多线程验证useful_proxy | ||
Author : J_hao | ||
date: 2017/9/26 | ||
------------------------------------------------- | ||
Change Activity: | ||
2017/9/26: 多线程验证useful_proxy | ||
------------------------------------------------- | ||
""" | ||
__author__ = 'J_hao' | ||
|
||
import sys | ||
from time import sleep | ||
from threading import Thread | ||
|
||
sys.path.append('../') | ||
|
||
from Util.utilFunction import validUsefulProxy | ||
from Manager.ProxyManager import ProxyManager | ||
from Util.LogHandler import LogHandler | ||
|
||
|
||
class ProxyCheck(ProxyManager, Thread): | ||
|
||
def __init__(self): | ||
ProxyManager.__init__(self) | ||
Thread.__init__(self) | ||
self.log = LogHandler('proxy_check') | ||
|
||
def run(self): | ||
self.db.changeTable(self.useful_proxy_queue) | ||
while True: | ||
proxy_item = self.db.pop() | ||
while proxy_item: | ||
proxy = proxy_item.get('proxy') | ||
counter = proxy_item.get('value') | ||
if validUsefulProxy(proxy): | ||
# 验证通过计数器加1, 计数在-5到1之间 | ||
if counter and int(counter) < 1: | ||
self.db.put(proxy, num=int(counter) + 1) | ||
else: | ||
self.db.put(proxy) | ||
self.log.info('ProxyCheck: {} validation pass'.format(proxy)) | ||
else: | ||
self.log.info('ProxyCheck: {} validation fail'.format(proxy)) | ||
# 验证失败,计数器减1 | ||
if counter and int(counter) < -5: | ||
self.log.info('ProxyCheck: {} fail too many, delete!'.format(proxy)) | ||
self.db.delete(proxy) | ||
else: | ||
self.db.put(proxy, num=int(counter) - 1) | ||
|
||
proxy_item = self.db.pop() | ||
sleep(60 * 5) | ||
|
||
|
||
if __name__ == '__main__': | ||
p = ProxyCheck() | ||
p.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.