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中的Numeric包和Numarray包使用教程

要了解 Numerical Python 软件包的第一件事情是,Numerical Python 不会让您去做标准 Python 不能完成的任何工作。它只是让您 以快得多的速度去完成标准...

Sanic框架基于类的视图用法示例

本文实例讲述了Sanic框架基于类的视图用法。分享给大家供大家参考,具体如下: 简介 基于类的视图只是实现对请求响应行为的类,他们提供了一种在同一端点上划分不同HTTP请求类型的处理方式...

python中kmeans聚类实现代码

k-means算法思想较简单,说的通俗易懂点就是物以类聚,花了一点时间在python中实现k-means算法,k-means算法有本身的缺点,比如说k初始位置的选择,针对这个有不少人提出...

python3 图片referer防盗链的实现方法

本篇文章主要破解referer防盗链技术 referer防盗链技术: referer防盗链技术是服务器通过检查客户端提起的请求包内的referer字段来阻止图片下载的,如果refere...

单利模式及python实现方式详解

单例模式 单例模式(Singleton Pattern)是一种常用的软件设计模式,该模式的主要目的是确保 某一个类只有一个实例存在 。当希望在整个系统中,某个类只能出现一个实例时,单例对...