-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproxy_requests.py
28 lines (25 loc) · 993 Bytes
/
proxy_requests.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
from anon_requests import ProxySession, NoMoreProxies, \
ProxyType, ProxyAnonymity
# validate=True will check if all proxies are functioning (default False)
# pass ignore_bad=False to not try the bad proxies at all (default True)
with ProxySession(proxy_type=ProxyType.HTTPS,
proxy_anonymity=ProxyAnonymity.ELITE) as session:
while True:
try:
response = session.get('https://ipecho.net/plain', timeout=5)
if response.status_code == 200:
print(response.text) # not your IP address
else:
pass # bad proxy
except KeyboardInterrupt:
break
except Exception as e:
#print("bad proxy, not working or very slow!")
#print(session.current_proxy)
#print(e)
pass
try:
session.rotate_identity() # new proxy
except NoMoreProxies:
print("used all available proxies")
break