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截取两个单词之间的内容方法

1. __init__ 初始化文件路径,关键字1,关键字2; 2. key_match 使用with open 方法,以二进制方式(也可以改成utf-8,GB2312)读取文件内容(支持...

详解Python3的TFTP文件传输

详解Python3的TFTP文件传输

TFTP文件传输 功能: 1、获取文件列表 2、上传文件 3、下载文件 4、退出 第一部分,TftpServer部分。 ①导入相关模块 from socket import * im...

遗传算法之Python实现代码

写在前面 之前的文章中已经讲过了遗传算法的基本流程,并且用MATLAB实现过一遍了。这一篇文章主要面对的人群是看过了我之前的文章,因此我就不再赘述遗传算法是什么以及基本的内容了,假设大家...

Python md5与sha1加密算法用法分析

本文实例讲述了Python md5与sha1加密算法。分享给大家供大家参考,具体如下: MD5 MD5的全称是Message-Digest Algorithm 5(信息-摘要算法),在9...

python模块smtplib学习

python的smtplib提供了一种很方便的途径发送电子邮件。它对smtp协议进行了简单的封装。 smtp协议的基本命令包括:     HELO 向服务...