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) 

相关文章

Pytorch中膨胀卷积的用法详解

Pytorch中膨胀卷积的用法详解

卷积和膨胀卷积 在深度学习中,我们会碰到卷积的概念,我们知道卷积简单来理解就是累乘和累加,普通的卷积我们在此不做赘述,大家可以翻看相关书籍很好的理解。 最近在做项目过程中,碰到Pytor...

朴素贝叶斯Python实例及解析

本文实例为大家分享了Python朴素贝叶斯实例代码,供大家参考,具体内容如下 #-*- coding: utf-8 -*- #添加中文注释 from numpy import *...

python ChainMap的使用和说明详解

ChainMap是Python collections模块中的一个成员,它用来将多个map组合到一起。Chain是链条的意思,字面意思就是把map串联到一起。 问题的背景是我们有多个字典...

python列表的增删改查实例代码

names=["zhao00","qian01","sun02","li03","li03","li03","zhou04"] #print(names[]) 打印错误 print(...

在centos7中分布式部署pyspider

1.搭建环境: 系统版本:Linux centos-linux.shared 3.10.0-123.el7.x86_64 #1 SMP Mon Jun 30 12:09:22 UTC 2...