作者在 2016-11-09 14:58:09 发布以下内容
公司安总让小弟做多人模拟绑定,于是就有了下文,非常简单,可以改下url做自动刷人气脚本
代码如下,请不要见笑
#-*- coding:utf-8 -*-
import requests, json, sqlite3, random,time,threading
from time import ctime
class BindOp(object):
def __init__(self):
global cookies
logindata = {
"username": "001",
"password": "000000"
}
s = requests.post("http://192.168.4.88:8080/shopweb/login",logindata)
cookies = s.cookies
print cookies
time.sleep(3)
def jb1(self):
print 'jb1 start' +ctime()
n = 0
jb1_eslid = open(r".\eslid1.txt").readlines() #数据格式为eslid+sku。eslid在前,sku号在后,中间不需要空格
for i in jb1_eslid:
n = n +1
i = i.strip('\n')
k = requests.post("http://192.168.4.88:8080/shopweb/bind",data=str([{"eslId": i[0:11],"goodsId":i[11:]}]),cookies = cookies)
print k.json()
time.sleep(6)
print 'jb1 over' +ctime()
def jb2(self):
print 'jb2 start' +ctime()
jb2_eslid = open("..\jb2\eslid2.txt").readlines() #脚本2的eslid
n = 0
for i in jb2_eslid:
n = n +1
i = i.strip('\n')
k = requests.post("http://192.168.4.88:8080/shopweb/bind",data=str([{"eslId": i[0:11],"goodsId":i[11:]}]),cookies = cookies)
print k.json()
time.sleep(6)
print 'jb2 over' +ctime()
def jb3(self):
n = 0
print 'jb3 start' +ctime()
time.sleep(1)
try:
jb3_eslid = open("..\jb3\eslid3.txt").readlines() #脚本3的eslid
for i in jb3_eslid:
n = n +1
i = i.strip('\n')
k = requests.post("http://192.168.4.88:8080/shopweb/bind",data=str([{"eslId": i[0:11],"goodsId":i[11:]}]),cookies = cookies)
print k.json()
time.sleep(6)
except:
print 'error,jb3 have been over,please try again'
finally:
print 'jb3 over' +ctime()
def jb4(self):
print 'jb4 start' +ctime()
n = 0
jb4_eslid = open("..\jb4\eslid4.txt").readlines() #脚本4的eslid
time.sleep(1)
for i in jb4_eslid:
n = n +1
i = i.strip('\n')
k = requests.post("http://192.168.4.88:8080/shopweb/bind",data=str([{"eslId": i[0:11],"goodsId":i[11:]}]),cookies = cookies)
print k.json()
time.sleep(6)
print 'jb4 over' +ctime()
def jb5(self):
print 'jb5 start' +ctime()
n = 0
jb5_eslid = open("..\jb5\eslid5.txt").readlines() #脚本5的eslid
time.sleep(1)
for i in jb5_eslid:
n = n +1
i = i.strip('\n')
k = requests.post("http://192.168.4.88:8080/shopweb/bind",data=str([{"eslId": i[0:11],"goodsId":i[11:]}]),cookies = cookies)
print k.json()
time.sleep(6)
print 'jb5 over' +ctime()
def jb6(self):
print 'jb6 start' +ctime()
n = 0
jb6_eslid = open("..\jb6\eslid6.txt").readlines() #脚本6的eslid
time.sleep(1)
for i in jb6_eslid:
n = n +1
i = i.strip('\n')
k = requests.post("http://192.168.4.88:8080/shopweb/bind",data=str([{"eslId": i[0:11],"goodsId":i[11:]}]),cookies = cookies)
print k.json()
time.sleep(6)
print 'jb6 over' +ctime()
def process(self):
threads = []
t1 = threading.Thread(target=BindOp.jb1,args=(self,))
threads.append(t1)
t2 = threading.Thread(target=BindOp.jb2,args=(self,))
threads.append(t2)
t3 = threading.Thread(target=BindOp.jb3,args=(self,))
threads.append(t3)
t4 = threading.Thread(target=BindOp.jb4,args=(self,))
threads.append(t4)
t5 = threading.Thread(target=BindOp.jb5,args=(self,))
threads.append(t5)
t6 = threading.Thread(target=BindOp.jb6,args=(self,))
threads.append(t6)
for tt in threads:
tt.start()
if __name__ == '__main__':
P= BindOp().process()