from threading import Thread from random import random from urllib2 im

 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
from threading import Thread
from random import random
from urllib2 import Request,urlopen
import socket
socket.setdefaulttimeout(1)
class WCrowder:
def __init__(self,url,p_list,user_agent='WCrowder/0.1'):
self.url=url
self.p_list=p_list
self.user_agent=user_agent
def crow(self,proxy):
p_addr,p_port=proxy
rnd=random()
req=Request(self.url)
req.add_header('User-agent','%s %s' %(self.user_agent,rnd))
req.add_header('Host', 'http://ya.ru')
req.set_proxy('%s:%s' %proxy,'http')
try:
print urlopen(req).read()
except Exception, ex:
print ex
return False
return True
def start(self,round_trip=False):
while True:
for proxy in self.p_list:
Thread(target=self.crow,args=(proxy,)).run()
if not round_trip:
break
c = WCrowder('http://ya.ru/', [('localhost', '9013'), ('localhost', '9014')])
c.start()