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后台管理程序

简单的python后台管理程序

一、作业需求   二、流程图 三、源码与具体思路 import shutil import os import sys USER_LOGIN = {'is_lo...

python使用配置文件过程详解

这篇文章主要介绍了python使用配置文件过程详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 通过配置文件将变量暴露给用户修改 标...

pygame实现弹力球及其变速效果

本文实例为大家分享了pygame实现弹力球及其变速效果的具体代码,供大家参考,具体内容如下 期望: 1.球体接触到框体后反弹 2.设置速度按键,按下后改变球体速度、颜色状态 具体实现:...

python3批量删除豆瓣分组下的好友的实现代码

python3批量删除豆瓣分组下的好友的实现代码 """ python3批量删除豆瓣分组下的好友 2016年6月7日 03:43:42 codegay 我两年前一时冲动在豆瓣关注了...

pycharm debug功能实现跳到循环末尾的方法

pycharm debug功能实现跳到循环末尾的方法

可以使用条件断点,如图,在断点上右键可以设置,条件自己输入,python语法: 以上这篇pycharm debug功能实现跳到循环末尾的方法就是小编分享给大家的全部内容了,希望能给大家...