python刷投票的脚本实现代码
原理就是用代理IP去访问投票地址。用到了多线程,速度飞快。
昨晚两个小时就刷了1000多票了,主要是代理IP不好找。
2.7环境下运行
#!/usr/bin/envpython
#-*-coding:utf-8-*-
importurllib2
fromthreadingimportThread
fromtimeimporttime
classVote(Thread):
def__init__(self,proxy):
Thread.__init__(self)
self.proxy=proxy
self.url='http://www.studentboss.com/zhuanti/2014/cncc/vote.php?id=19'
self.timeout=10
defrun(self):
proxy_handle=urllib2.ProxyHandler({"http":r'http://%s'%self.proxy})
opener=urllib2.build_opener(proxy_handle)
urllib2.install_opener(opener)
try:
req=urllib2.urlopen(self.url,timeout=self.timeout)
result=req.read().decode('gbk')
printresult
pos=result.find(u'成功')
ifpos>1:
addnum()
else:
pass
exceptException,e:
printe.message,'error'
defaddnum():
globaln
n+=1
defshownum():
returnn
n=0
threads=[]
proxylist=open('proxy.txt','r')
forproxyinproxylist:
t=Vote(proxy)
threads.append(t)
if__name__=='__main__':
start_time=time()
foriinthreads:
i.start()
foriinthreads:
i.join()
print'%svoteshavebeenvotedsuccessfullyusing%sseconds'%(shownum(),time()-start_time)