-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproxy.py
66 lines (57 loc) · 1.83 KB
/
proxy.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from lxml.html import fromstring
import requests
from itertools import cycle
import traceback
import sys
import urllib.request, socket
from threading import Thread
#programm to scrape website( free-proxy-list.net) for proxies
class proxies:
def __init__(self, n_proxies=50):
self._n_proxies= n_proxies
self._proxies= None
def get_proxies(self):
url = 'https://free-proxy-list.net/'
response = requests.get(url)
parser = fromstring(response.text)
proxies = set()
for i in parser.xpath('//tbody/tr'):
if i.xpath('.//td[7][contains(text(),"yes")]'):
proxy = ":".join([i.xpath('.//td[1]/text()')[0], i.xpath('.//td[2]/text()')[0]])
proxies.add(proxy)
return proxies
def getproxy(self):
if self._proxies==None:
proxy_pool=cycle(self.get_proxies())
self._proxies=1
proxy_pool=next(proxy_pool)
return proxy_pool
def check_proxy(self,pip,teller):
try:
proxy_handler = urllib.request.ProxyHandler({'https': pip})
opener = urllib.request.build_opener(proxy_handler)
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
urllib.request.install_opener(opener)
current_tile=str(teller) # change the url address here
urllib.request.urlretrieve('http://mt0.google.com/vt?lyrs=s&x='+str(133128+teller)+'&y=88009&z=18', current_tile)
im = Image.open(current_tile)
im.save(str(teller)+".jpg")
print(teller)
print(pip)
except urllib.error.HTTPError as e:
return e
except Exception as detail:
return detail
return 0
proxie=proxies()
socket.setdefaulttimeout(30)
proxe=proxie.get_proxies()
threads=[]
#prox=cycle(proxe)
for teller,proxy in enumerate(proxe):
thread = Thread( target=proxie.check_proxy, args=(proxy.strip(),teller,))
print(proxy.strip(),)
thread.start()
threads.append(thread)
for thread in threads:
thread.join()