python刷投票的脚本实现代码

yipeiwu_com5年前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中的元祖(Tuple)和字典(Dict)

前言 本文记录了对于Python的数据类型中元祖(Tuple)和字典(Dict)的一些认识,以及部分内置方法的介绍。下面话不多说,来看看详细的介绍吧。 元祖 Tuple 特点:元祖内的数...

python安装与使用redis的方法

本文实例讲述了python安装与使用redis的方法。分享给大家供大家参考,具体如下: 1、安装 好吧,我承认我只会最简单的安装: sudo apt-get install redi...

Python实现读取邮箱中的邮件功能示例【含文本及附件】

本文实例讲述了Python实现读取邮箱中的邮件功能。分享给大家供大家参考,具体如下: #-*- encoding: utf-8 -*- import sys import local...

Python设计模式之职责链模式原理与用法实例分析

Python设计模式之职责链模式原理与用法实例分析

本文实例讲述了Python设计模式之职责链模式原理与用法。分享给大家供大家参考,具体如下: 职责链模式(Chain Of Responsibility):使多个对象都有机会处理请求,从而...

浅析Python中return和finally共同挖的坑

前言 本文主要给大家介绍了在Python中return和finally共同存在的坑,以及填坑经验,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧。 初识 return...