python刷投票的脚本实现代码

yipeiwu_com6年前Python基础

原理就是用代理IP去访问投票地址。用到了多线程,速度飞快。
昨晚两个小时就刷了1000多票了,主要是代理IP不好找。

2.7环境下运行

#!/usr/bin/env python 
#-*- coding: utf-8 -*- 
 
import urllib2 
from threading import Thread 
from time import time 
 
class Vote(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
 
    def run(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') 
            print result 
            pos = result.find(u'成功') 
            if pos > 1: 
                addnum() 
            else: 
                pass
        except Exception,e: 
            print e.message,'error'    
 
 
def addnum(): 
    global n 
    n += 1
 
def shownum(): 
    return n 
 
n = 0
 
threads = [] 
 
proxylist = open('proxy.txt', 'r') 
 
for proxy in proxylist: 
    t = Vote(proxy) 
    threads.append(t) 
 
 
if __name__ == '__main__': 
    start_time = time() 
    for i in threads: 
        i.start() 
    for i in threads: 
        i.join() 
    print '%s votes have been voted successfully using %s seconds' % (shownum(), time()-start_time) 

相关文章

Python实现获取本地及远程图片大小的方法示例

Python实现获取本地及远程图片大小的方法示例

本文实例讲述了Python实现获取本地及远程图片大小的方法。分享给大家供大家参考,具体如下: 了解过Pillow的都知道,Pillow是一个非常强大的图片处理器,这篇文章主要记录一下Pi...

Python 开发Activex组件方法

使用win32com模块开发window ActiveX的示例:(如果你还没有装win32com模块的话,请到http://python.net/crew/skippy/win32/Do...

解决Python列表字符不区分大小写的问题

有时候,我们需要检测一个元素是否已经存在列表中,并且不区分大小写,如:列表已有元素Mary,那我们想认为MARY也已经被占用。这个例子在实际编程中会用到很多,比如保证网站注册用户独一无二...

python多进程并发demo实例解析

这篇文章主要介绍了python多进程并发demo实例解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 前言 下午需要简单处理一份数据...

Python实现复杂对象转JSON的方法示例

本文实例讲述了Python实现复杂对象转JSON的方法。分享给大家供大家参考,具体如下: 在Python对于简单的对象转json还是比较简单的,如下: import json d =...