Python多线程自动刷票脚本

#!/usr/bin/python  
# -*- coding: utf-8 -*-  
#coding=utf-8
import urllib2
import urllib
import re
import threading
from time import ctime
rlock = threading.RLock()
#myproxy代理地址
# i线程id
def vote(myproxy,i):
	try:
		print "voting...%d..." % i
		#采用代理ip发送数据
		proxy_support = urllib2.ProxyHandler(myproxy)
		opener = urllib2.build_opener(proxy_support, urllib2.HTTPHandler)
		urllib2.install_opener(opener)

		sendt = '投票'.decode('utf-8').encode('gb2312')
		#发送数据目标地址
		url = '' 
		#post数据
		values = {}  
		req = urllib2.Request(url,urllib.urlencode(values)) 
		response = opener.open(req) 
		html = response.read() 
		#print html
		if html.find('投票人数过多'.decode('utf-8').encode('gb2312')):
			print "VOTE %d Faild Plase wait a minute" % i
			return False
		else:
			print "VOTE %d Success" % i
			return Ture
	except Exception:
		print " Error The %d proxy cann't do anything" % i
		return False

if __name__ == "__main__":
	#读取ip.txt文件 ip格式:1.179.128.2:8080@HTTP#泰国
	ipFile = open('ip.txt')
	ipList = ipFile.readlines()
	ipFile.close()

	length = range(len(ipList))
	#print length
	threads = []
	for i in length:
		ipLine = ipList[i]
		stringList = ipLine.split('@')
		ip=stringList[0]
		myproxy = {'http': ip}
		#print myproxy
		t = threading.Thread(target=vote,args=(myproxy,i))
		threads.append(t)
	for i in length:
		threads[i].start()

	for i in length:
		threads[i].join()
	
	print "all done at", ctime()
	
		

转自:http://blog.csdn.net/cnairng/article/details/11924169


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值