def check_proxy(self, proxy_list):
ava_list = []
test_url = "http://www.baidu.com/"
for host, port in proxy_list:
ret = False
host_port = "%s:%s" % (host, port)
proxy = {
"http": "http://%s" %(host_port),
"https": "https://%s" %(host_port),
}
proxy_handler = urllib2.ProxyHandler(proxy)
opener = urllib2.build_opener(proxy_handler)
try:
conn = opener.open(test_url, timeout=2.5)
data = conn.read()
if "??" in data:
ret = True
ava_list.append((host, port))
except Exception as e:
# print e
ret = False
print "checking proxy: %s ---> %s" % (host_port, str(ret))
return ava_list
评论列表
文章目录