首页 > 代码库 > 构造数据包进行批量用户注册

构造数据包进行批量用户注册

 长知识:

现大部分服务端、客户端都默认是将数据进行UTF-8编码,但是当客户端向服务端发送的数据包中含有中文时,一定在headers中说明charset,否则服务器端知道要用什么编码方式解码。而英文、数字等一般服务器端默认用UTF-8解码。

 

#coding:UTF-8import urllib2import urllibimport cookielibimport jsonimport sysimport shutilimport xlrdimport chardetimport osimport timeimport randomstdout = sys.stdoutreload(sys)sys.setdefaultencoding(utf-8)sys.stdout = stdoutcookie = cookielib.CookieJar()opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie)) data = xlrd.open_workbook(rc:\fuck\1.xls)table = data.sheets()[0]num = 100000000for i in range(0,11):    name = table.cell(i,0).value[-1]    name = name + name    mail = table.cell(i,2).value        for j in range(0,11):        tnum = unicode(num)        sname = name        name2 = table.cell(j,1).value;        sname = sname + name2        if(len(sname)<=27):            sname = unicode("")+sname                        #需要POST的数据#          postdata=http://www.mamicode.com/urllib.urlencode({                stuDep:计算机学院,                stuId:tnum,            stuMail:mail,            stuName:sname,            stuPhone:12345678901        })        headerss = {Content-Type:                   application/x-www-form-urlencoded; charset=UTF-8                   };                #自定义一个请求#          req = urllib2.Request(                url = http://172.31.150.21/ACMRegister/test.json,                data = postdata ,             headers = headerss        )                 #访问该链接          result = opener.open(req)                    print sname +  finished.   +result.read()                num += 1                    dd = random.random()        yy = random.randint(0,1)        time.sleep(dd+yy)

 

构造数据包进行批量用户注册