玩蛇网提供最新Python编程技术信息以及Python资源下载!

python实现的58同城批量注册机源码片段

python 培训

以下是一位学习python编程语言爱好者用了二小时弄的实现的58同城批量注册机源码片段。肯定还有不足之处,和喜欢动手敲代码的python爱好者们一同分享。要正式使用还需要进行修改才行。

reg.py

#coding=utf-8
import urllib2 as request,urllib as parse,cookielib,random
import os,random,re,time
import json.encoder as json_encode,json.decoder as json_decode
class Api_connect:
        #API CONNECT QQ SOCKET
    __headers = {
        'User-Agent':'Mozilla/6.0 (Windows NT 6.1; WOW64) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.9 Safari/534.30',\
        'Referer':'http://www.58.com'\
    }
    __data = {
        'cookiepath':'cookie.txt'
    } #登陆以后存放数据
    __http = {} #http进程信息
    __version__ = '1.0'
    def __init__(self,proxy={}):
        self.__proxy = proxy
        self.__httpproess()
    def __httpproess(self):
        #初始化模拟进程
        proxy_support = request.ProxyHandler(self.__proxy)
        self.__http['cj'] = cookielib.MozillaCookieJar(self.__data['cookiepath'])
        self.__http['opener'] = request.build_opener(proxy_support,request.HTTPCookieProcessor(self.__http['cj']))
        pass
    def urlopen(self,url,method='GET',data={},savecookie=False):
        try:
            if (method).upper() == 'POST':
                data = parse.urlencode(data).encode('utf-8')
                self.__http['req'] = request.Request(url,data,self.__headers)
            else:
                self.__http['req'] = request.Request(url=url,headers=self.__headers)
            fp = self.__http['opener'].open(fullurl=self.__http['req'],timeout=5)
            t= fp.read()
            try:
                str = t.decode('utf-8')
            except UnicodeDecodeError:
                str = t
            if savecookie == True:
                self.__http['cj'].save(ignore_discard=True,ignore_expires=True)
            fp.close()
            return str
        except Exception as e:
            return '{}'
    def getForm(self,str):
        if str.find(u'58同城') != -1:
            r = str.index('<form')
            o = str.index('</form>')
            return str[r:o]
        return None
    def getFormValue(self,name,str):
        str2 = re.findall(r'\<input.+name\=\"'+ name +'\".+value=\".+\"\/\>',str)
        findstr = 'value="'
        u1 = str2[0].find(findstr)
        u2 = str2[0].find('"/>')
        return str2[0][u1+len(findstr):u2]
        pass
    def __del__(self):
        pass

class reg(object):
    reg = {'reg_page':'http://passport.58.com/reg/','post_page':'http://passport.58.com/save/','check_page':'http://passport.58.com/regok?regok=1'}
    proxy ={}
    def __init__(self):
        self.regfile = file('reg.txt','wb')
    def setproxy(self,list):
        fp = open(list,'rb')
        self.proxy = fp.readlines()
        self.proxy = [i.rstrip() for i in self.proxy]
        fp.close()
    def getproxy(self):
        return {"http":"http://"+self.proxy[random.randint(0,len(self.proxy)-1)]}
    def setinfo(self,info = []):
        self.info = info
        pass
    def setfile(self,file):
        fp = open(file,'rb')
        self.info = fp.readlines()
        fp.close()
    def reg_load(self,username,password,email):
        if len(self.proxy) != 0:
            ip = self.getproxy()
        else:
            ip ={}
        self.t = Api_connect(ip)
        str = self.t.urlopen(url=self.reg['reg_page'],savecookie=True)
        if str == '{}':
            print u'代理ip错误',ip
            ip = self.getproxy()
            self.t = Api_connect(ip)
            str = self.t.urlopen(url=self.reg['reg_page'],savecookie=True)
        form = self.t.getForm(str)
        if form == None:
            print u'表单错误,太频繁胃'
            return
        postdata = {'nickName':'%s'%username,'txtemail':'%s'%email,'password':'%s'%password,'cpassword':'%s'%password,'cd':self.t.getFormValue('cd',form),'ptk':self.t.getFormValue('ptk',form)}
        self.t.urlopen(url=self.reg['post_page'],method='POST',data=postdata,savecookie=True)
        str = self.t.urlopen(url=self.reg['check_page'],savecookie=True)
        info="用户名:{0},密码:{1},邮箱:{2}".format(username,password,email)
        uinfo = u"用户名:{0},密码:{1},邮箱:{2}".format(username,password,email)
        if str.find(u'注册成功') != -1:
            print >> self.regfile,info
            print uinfo,u',注册成功!'
        else:
            print uinfo,u',注册失败!'
        del self.t
    def reg_start(self):
        for i in self.info:
            self.reg_load(*i.rstrip().sp
2000
lit(" "))

#www.iplaypython.com
            
if __name__ == "__main__":
    reg =reg()
    reg.setfile('user.txt')
    reg.setproxy('Proxies.txt')
    reg.reg_start()

以下是代理:
116.236.205.100:80
119.97.146.152:80
222.165.175.118:80
120.35.31.101:8080
124.193.109.117:80
219.134.240.203:80
122.226.240.235:80
59.57.15.71:80
180.137.45.86:8080
180.139.91.27:8080
202.103.215.199:80
202.105.233.40:80
222.73.25.121:6666
222.74.212.66:808
122.225.107.20:80
122.225.107.21:80
122.225.107.27:80
60.190.77.98:3128
60.250.109.87:3128
82.222.49.81:8080
119.145.197.69:8080
121.8.209.190:3128
202.43.179.182:54321
218.6.13.35:80
203.66.83.46:3128
82.222.19.54:8080
60.191.220.241:3128
219.159.105.180:8080
218.22.80.61:3128
218.16.145.109:8080
61.166.155.230:8080
118.112.185.71:8080
121.12.250.201:3128
222.83.210.45:8080
122.225.22.22:8080
61.157.217.31:80
82.222.49.65:8080
122.226.240.233:80
82.222.48.1:8080
59.172.208.186:8080
218.94.149.114:8080
115.236.98.109:80
122.72.1.118:80
122.72.112.184:80
222.184.9.242:3128
119.161.238.90:80
203.66.187.246:81
61.136.59.177:80
203.66.187.246:88
219.133.36.198:80
111.1.33.138:80
111.1.32.10:80
122.48.31.78:80
111.1.32.4:80
202.98.123.126:8080
211.138.124.203:80
221.130.23.104:80
111.1.32.20:80
211.138.124.175:80
203.66.187.246:80
221.130.18.80:80
180.96.19.24:8080
122.72.11.129:80
118.112.185.71:8080
221.130.18.93:80
221.130.18.78:80
219.145.93.110:8080
180.139.91.27:8080
120.203.214.177:80
203.66.188.250:80
121.33.249.170:8080
124.160.239.234:80
120.203.215.16:80
221.130.18.51:80
218.152.121.184:8080
61.135.208.184:80
111.1.32.29:80
210.53.53.101:80
111.1.32.7:80
202.169.62.139:8080
115.236.98.109:80
111.1.32.16:80
173.242.123.4:80
218.201.21.176:80
119.59.100.105:3128
58.137.98.211:80
211.138.124.199:80
122.72.112.166:80
211.76.97.152:80
60.28.186.114:80
78.85.39.109:3128
211.138.124.211:80
218.247.138.40:80
211.76.97.146:80
211.76.97.150:80
186.228.41.210:8080
72.64.146.135:3128
195.96.85.61:8080
202.77.107.110:8082
124.160.239.223:80
118.97.75.226:8080

玩蛇网原创,转载请注明文章出处和来源网址:http://www.iplaypython.com/code/other/o2235.html



微信公众号搜索"玩蛇网Python之家"加关注,每日最新的Python资讯、图文视频教程可以让你一手全掌握。强烈推荐关注!

微信扫描下图可直接关注

玩蛇网Python新手QQ群,欢迎加入: ① 240764603 玩蛇网Python新手群
文章发布日期:2016-05-17 15:06 玩蛇网 www.iplaypython.com

评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
相关文章推荐
别人正在看
特别推荐
去顶部去底部