-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfetch-proxies.py
executable file
·44 lines (33 loc) · 997 Bytes
/
fetch-proxies.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
40
41
42
43
44
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) JoinQuant Development Team
# Author: Huayong Kuang <[email protected]>
"""
获取代理
基于 https://github.com/constverum/ProxyBroker
"""
import asyncio
import requests
from proxybroker import Broker
requests.adapters.DEFAULT_RETRIES = 0
async def show(proxies):
while True:
proxy = await proxies.get()
if proxy is None: break
try:
resp = requests.get("https://google.com", timeout=5, proxies={
'http': f'socks5://{proxy.host}:{proxy.port}',
'https': f'socks5://{proxy.host}:{proxy.port}'
})
resp.raise_for_status()
except Exception as e:
continue
print('Found proxy: %s' % proxy)
proxies = asyncio.Queue()
broker = Broker(proxies)
tasks = asyncio.gather(
broker.find(types=['SOCKS5'], limit=1<<20),
show(proxies)
)
loop = asyncio.get_event_loop()
loop.run_until_complete(tasks)