def run(self): global th while 1: i = 0 errc = 0 try: # proxy = proxies.getProxy() # session = Session(proxy) session = Session() except: print 'read proxy or session error' exstr = traceback.format_exc() print exstr while 1: try: i += 1 if (i % 30 == 0): # session = Session(proxy) session = Session() res = Loginer.post(session, netease) con = res.read() print con errc = 0 if json.loads(con)['code'] == 200: print con if json.loads(con)['code'] == 500: # print 'break and switch new proxy' break except: errc += 1 # print 'error! count: '+ str(errc) if errc > th: exstr = traceback.format_exc() # print exstr break
def run(self): while 1: try: proxy = f.readline() if not proxy: break session = Session(proxy) i = 0 errc = 0 except: print 'read file or session error' while 1: try: i += 1 if (i % 30 == 0): session = Session(proxy) res = session.open( 'http://newyear.music.163.com/web/activity/vote/toupiao', payload) con = res.read() print con errc = 0 if json.loads(con)['code'] == 500: print 'break and switch new proxy' break except: errc += 1 print 'error! count: ' + str(errc) if errc > th: exstr = traceback.format_exc() print exstr break
def run(self): global g_header, th, g_post, g_url,proxies, f, arr while 1: i=0 errc=0 try: proxy = proxies.getProxy() session = Session(proxy) # session = Session() except: print 'read proxy or session error' exstr = traceback.format_exc() print exstr while 1: try: i+=1 res = session.open('http://www.xingdiandian.com/', time_out=8) con=res.read() csrf = con[con.find('csrf-token')-52:con.find('csrf-token')-8] # print con post = Loginer.HttpRequest() post.header = dict(g_header) post.header['X-CSRF-Token'] = csrf post.url = g_url for startid in arr: post.post = g_post+str(startid) wait=1 while wait<10 and wait!=0: if wait>1: print 'sleeping (' +str(wait) + ')+1 secs to post again---' time.sleep(wait) res = Loginer.post(session, post) con=res.read() params = con.split(';') wait = int(params[4]) print str(startid)+'||'+con # print >>f, proxy # if i%5==0: # f.flush() session.opener.close() errc=0 break # if json.loads(con)['code']==200: # print con # if json.loads(con)['code']==500: # # print 'break and switch new proxy' # break except: errc+=1 # print 'error! count: '+ str(errc) if errc>th: exstr = traceback.format_exc() session.opener.close() # print exstr break
def run(self): while 1: line = f.readline() if not line: break s = Session(line,0) try: res = s.open('http://weibo.com', time_out=7) print 'proxy: ' + line + '========' + str(res.getcode()) if res.getcode()==200: print >>f2, line[:-1] except: print 'proxy: ' + line + '======== time out'
def run(self): global proxies global th global pollnum global count global lock global pcount, f, headers, index, pollUrl c = 0 while 1: i = 1 errc = 0 try: proxy = proxies.getProxy() # print 'thread using proxy: ' + proxy session = Session(proxy) # session = Session() except: # print 'read proxy or session error' # exstr = traceback.format_exc() # print exstr continue while 1: try: # if i%(pollnum+1)==0: # print >> f, proxy # pcount+=1 # if pcount%50==0: # f.flush() # break # session = Session() # res = session.open(pollUrl2+str(int(time.time()*1e3)), time_out=10) req = HttpRequest() req.header = headers req.url = index res = Loginer.get(session, req) for i in range(pollnum): req.url = pollUrl + str(4 + i) res = Loginer.get(session, req) con = res.read() print con # c+=1 # i+=1 # print con errc = 0 break # if c%30==0: # lock.acquire() # count += c # c=0 # print '==========voted ' + str(count) + ' times!' # lock.release() except: errc += 1 # print 'error! count: '+ str(errc) if errc > th: exstr = traceback.format_exc() # print exstr break
def login(self, username, password, is_proxy=False): if postdata.get('door') != None: del postdata['door'] if is_proxy: proxy = self.proxyQueue.getProxy() self.session = Session(proxy) else: self.session = Session() # prelogin res = self.session.open(self.servertimeUrl, time_out=5) t = long(time.time() / 1000) con = res.read() self.prelogin = eval(con[35:-1]) servertime = self.prelogin['servertime'] pubkey = self.prelogin['pubkey'] nonce = self.prelogin['nonce'] su = base64.encodestring(urllib.quote(username))[:-1] servertime = servertime + long(long(servertime) / 1000) - t sp = self.sinaEncryptMsg(pubkey, password, servertime, nonce) postdata['nonce'] = nonce postdata['servertime'] = servertime postdata['su'] = su postdata['sp'] = sp postdata['rsakv'] = self.prelogin['rsakv'] self.pcid = self.prelogin['pcid'] postdata['pcid'] = self.prelogin['pcid'] login_data = urllib.urlencode(postdata) res = self.session.open(self.loginUrl, login_data, time_out=5) con = res.read() last = con.find('&', con.find('retcode=')) if last != -1: retcode = con[con.find('retcode=') + 8:last] else: retcode = con[con.find('retcode=') + 8:con.find('retcode=') + 9] print username + ':' + password + ':' + retcode if retcode != '0': print 'login failed' print con return retcode redirectUrl = con[con.find('location.replace(\'') + 18:con.find('retcode=0') + 9] self.session.open(redirectUrl, login_data, time_out=5) return retcode
def run(self): while 1: line = f.readline() if not line: break username = line[line.rfind('# ') + 2:-2] password = line[line.find('# ') + 2:line.rfind(' #')] index = 0 try: while 1: index = int(random.random() * count) if valids[index]: locks[index].acquire() if valids[index]: locks[index].release() break proxy = proxies[index] s = Session(proxy, 0) s.open('http://weibo.com/') res = s.open(servertimeUrl) t = long(time.time() / 1000) con = res.read() js = eval(con[35:-1]) servertime = js['servertime'] pubkey = js['pubkey'] nonce = js['nonce'] su = base64.encodestring(urllib.quote(username))[:-1] servertime = servertime + long(long(servertime) / 1000) - t sp = sinaEncryptMsg(pubkey, password, servertime, nonce) postdata['nonce'] = nonce postdata['servertime'] = servertime postdata['su'] = su postdata['sp'] = sp postdata['rsakv'] = js['rsakv'] login_data = urllib.urlencode(postdata) res = s.open(loginUrl, login_data) con = res.read() retcode = con[con.find('retcode=') + 8:con.find('&', con.find('retcode='))] print username + ':' + password + ':' + retcode if retcode == '0': print >> f2, username + ':' + password + ':success' else: print >> f2, username + ':' + password + ':failed' + retcode f2.flush() except: exstr = traceback.format_exc() print exstr print 'proxy failed!' + proxy print 'invalidating proxy: ' + proxy locks[index].acquire() valids[index] = False locks[index].release()
def run(self): global g_header, th, g_post, g_url,proxies, f, arr while 1: i=0 errc=0 try: # proxy = proxies.getProxy() # session = Session(proxy) session = Session() except: print 'read proxy or session error' exstr = traceback.format_exc() print exstr while 1: try: req = Loginer.HttpRequest() req.header=g_header req.url=g_url for post in arr: req.post=post res = Loginer.post(session, req) print res.read() # print >>f, proxy # if i%5==0: # f.flush() session.opener.close() # if json.loads(con)['code']==200: # print con # if json.loads(con)['code']==500: # # print 'break and switch new proxy' # break except: errc+=1 # print 'error! count: '+ str(errc) if errc>th: exstr = traceback.format_exc() session.opener.close() # print exstr break
class SinaLogin(object): def __init__(self): self.pubkey = 'EB2A38568661887FA180BDDB5CABD5F21C7BFD59C090CB2D245A87AC253062882729293E5506350508E7F9AA3BB77F4333231490F915F6D63C55FE2F08A49B353F444AD3993CACC02DB784ABBB8E42A9B1BBFFFB38BE18D78E87A0E41B9B8F73A928EE0CCEE1F6739884B9777E4FE9E88A1BBE495927AC4A799B3181D6442443' self.servertimeUrl = 'http://login.sina.com.cn/sso/prelogin.php?entry=weibo&callback=sinaSSOController.preloginCallBack&su=&rsakt=mod&client=ssologin.js(v1.4.18)&_=' + str( long(time.time() * 1000)) self.loginUrl = 'http://login.sina.com.cn/sso/login.php?client=ssologin.js(v1.4.18)' self.session = None self.pcid = '' self.proxyQueue = ProxyQueue(is_thread=False) self.prelogin = {} def sinaEncryptMsg(self, pubkey, msg, servertime, nonce): rsaPublickey = int(pubkey, 16) key = rsa.PublicKey(rsaPublickey, 65537) message = str(servertime) + '\t' + str(nonce) + '\n' + str(msg) passwd = rsa.encrypt(message, key) passwd = binascii.b2a_hex(passwd) return passwd def login(self, username, password, is_proxy=False): if postdata.get('door') != None: del postdata['door'] if is_proxy: proxy = self.proxyQueue.getProxy() self.session = Session(proxy) else: self.session = Session() # prelogin res = self.session.open(self.servertimeUrl, time_out=5) t = long(time.time() / 1000) con = res.read() self.prelogin = eval(con[35:-1]) servertime = self.prelogin['servertime'] pubkey = self.prelogin['pubkey'] nonce = self.prelogin['nonce'] su = base64.encodestring(urllib.quote(username))[:-1] servertime = servertime + long(long(servertime) / 1000) - t sp = self.sinaEncryptMsg(pubkey, password, servertime, nonce) postdata['nonce'] = nonce postdata['servertime'] = servertime postdata['su'] = su postdata['sp'] = sp postdata['rsakv'] = self.prelogin['rsakv'] self.pcid = self.prelogin['pcid'] postdata['pcid'] = self.prelogin['pcid'] login_data = urllib.urlencode(postdata) res = self.session.open(self.loginUrl, login_data, time_out=5) con = res.read() last = con.find('&', con.find('retcode=')) if last != -1: retcode = con[con.find('retcode=') + 8:last] else: retcode = con[con.find('retcode=') + 8:con.find('retcode=') + 9] print username + ':' + password + ':' + retcode if retcode != '0': print 'login failed' print con return retcode redirectUrl = con[con.find('location.replace(\'') + 18:con.find('retcode=0') + 9] self.session.open(redirectUrl, login_data, time_out=5) return retcode def getPinCode(self): res = self.session.open(pipUrl + '?r=' + str(int(math.floor(random.random() * 1e8))) + '&s=0&p=' + self.pcid) return res.read() def relogin(self, username, password, code): servertime = self.prelogin['servertime'] pubkey = self.prelogin['pubkey'] nonce = self.prelogin['nonce'] su = base64.encodestring(urllib.quote(username))[:-1] servertime = servertime sp = self.sinaEncryptMsg(pubkey, password, servertime, nonce) postdata['su'] = su postdata['sp'] = sp postdata['door'] = code login_data = urllib.urlencode(postdata) res = self.session.open(self.loginUrl, login_data, time_out=5) con = res.read() last = con.find('&', con.find('retcode=')) if last != -1: retcode = con[con.find('retcode=') + 8:last] else: retcode = con[con.find('retcode=') + 8:con.find('retcode=') + 9] print username + ':' + password + ':' + retcode return retcode