This a test paper

P ython脚本:用代理刷投票页面  2010-09-12 01:07:22

分类: 系统运维

首先是一个初始多线程以及设置代理地址的地方,我称他为kk2.py

import urllib2,cookielib
import urllib, time, string
import threading

####创建线程#

class PrintThread(threading.Thread):

    def __init__(self,threadname):
        threading.Thread.__init__(self)
        self.sleepTime = (1)
        self.name = threadname
####创建线程任务   ###    
    def run(self):
       App().runnum()    #任务是执行下面的读页面操作


class App(PrintThread):
    def __init__(self):
        self.cookie=cookielib.CookieJar()
        self.opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cookie))
        urllib2.install_opener(self.opener)

#设置代理服务器地址,网上大把,下面的不一定能用
        self.proxy = ['http://125.244.164.69:8080','http://125.245.226.2:8080','http://125.248.244.131:8080',
                      'http://125.250.30.82:8081',
                      'http://125.31.236.243:3128',
                      'http://125.64.33.25:80',
                      'http://125.90.64.72:80',
                      'http://125.90.64.74:80',
                      'http://142.red-213-37-2.user.auna.net:8080',
                      'http://163.28.33.226:3128',
                      'http://163.28.33.226:8088',
                      'http://194.204.111.94:3128',
                      'http://195.175.37.6:8080',
                      'http://195.175.37.70:80',
                      'http://195.175.37.70:8080',
                      'http://195.175.37.71:80']
    def runnum(self):       

### 用for来循环使用代理服务器
        for self.x in range(len(self.proxy)):
            self.MYPROXY={'http':self.proxy[self.x]}
            print self.MYPROXY

### 真正开始利用代理读页面
            try:
                self.login_response= urllib.urlopen(r'http://xy2.163.com/php/trueshow/vote.php?id=85614',proxies = self.MYPROXY) #

                ll=self.login_response.read()
            except IOError:    #如果代理服务器不可用再跳至下一个代理地址继续读页面
                print "Error,The proxy cann't to do anything,try next... "
                self.x =+1

if __name__=='__main__':
    App().runnum()

下面是真正运行并指定连接数的文件,我叫他121y.py

import urllib2,cookielib
import urllib, time, string
import datetime

## 启动多线程任务 
while True:
    import kk2
    for x in range(1,100):
        t1=kk2.PrintThread(str(x))
        print str(x)+':::', datetime.datetime.now()
        t1.start()

在这里设置了多线程共同操作的内容以及提示,写完收功,启动程序看到你刷新的地址的浏览量每10秒成百上千的加

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值