def __init__(self, agent_addr, *, min_success_rate=.0, min_count=0,
update_interval=300, auth=None, params=None, timeout=20, loop=None):
"""
SimpleProxyPool constructor.
agent_addr - Proxy agent address.
min_success_rate - (optional) The minimum acceptable success rate of a proxy.
min_count - (optional) The least number of proxies in the proxy list.
It works when pass the `min_success_rate` parameter.
update_interval - (optional) Time interval to update the proxy list from proxy agent.
auth - (optional) Http Basic Auth tuple.
params - (optional) Prameters dictionary be sent in the query.
timeout - (optional) Timeout when connects proxy agent.
loop - (optional) Event loop.
"""
self.agent_addr = agent_addr
if loop is None:
self.asyn = False
self.loop = asyncio.new_event_loop()
else:
self.asyn = True
self.loop = loop
self.auth = auth
if self.auth is not None:
if isinstance(self.auth, tuple):
self.auth = aiohttp.BasicAuth(*self.auth)
elif not isinstance(self.auth, aiohttp.BasicAuth):
raise TypeError('The type of "auth" must be tuple or aiohttp.BasicAuth')
self.params = params or {}
self.timeout = timeout
self.update_interval = update_interval
self.min_success_rate = min_success_rate
self.min_count = min_count
self._last_update = 0
self._update_lock = asyncio.Lock(loop=self.loop)
self.proxies = []
评论列表
文章目录