自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

如何科學(xué)的搶紅包:寫個程序搶紅包

移動開發(fā)
背景大家都懂的,要過年了,正是紅包滿天飛的日子。正巧前兩天學(xué)會了Python,比較亢奮,就順便研究了研究微博紅包的爬取,為什么是微博紅包而不是支付寶紅包呢,因為我只懂Web,如果有精力的話之后可能也會研究研究打地鼠算法吧。

背景大家都懂的,要過年了,正是紅包滿天飛的日子。正巧前兩天學(xué)會了Python,比較亢奮,就順便研究了研究微博紅包的爬取,為什么是微博紅包而不是支付寶紅包呢,因為我只懂Web,如果有精力的話之后可能也會研究研究打地鼠算法吧。

因為本人是初學(xué)Python,這個程序也是學(xué)了Python后寫的第三個程序,所以代碼中有啥坑爹的地方請不要當(dāng)面戳穿,重點是思路,嗯,如果思路中有啥坑爹的的地方也請不要當(dāng)面戳穿,你看IE都有臉設(shè)置自己為默認(rèn)瀏覽器,我寫篇渣文得瑟得瑟也是可以接受的對吧……

我用的是Python 2.7,據(jù)說Python 2和Python 3差別挺大的,比我還菜的小伙伴請注意。

0×01 思路整理

懶得文字?jǐn)⑹隽耍嬃藦埐輬D,大家應(yīng)該可以看懂。

首先老規(guī)矩,先引入一坨不知道有啥用但又不能沒有的庫:

  1. import re 
  2. import urllib 
  3. import urllib2 
  4. import cookielib 
  5. import base64  
  6. import binascii  
  7. import os 
  8. import json 
  9. import sys  
  10. import cPickle as p 
  11. import rsa 

然后順便聲明一些其它變量,以后需要用到:

  1. reload(sys) 
  2. sys.setdefaultencoding('utf-8&') #將字符編碼置為utf-8 
  3. luckyList=[] #紅包列表 
  4. lowest=10 #能忍受紅包領(lǐng)獎記錄最低為多少 

這里用到了一個rsa庫,Python默認(rèn)是不自帶的,需要安裝一下:https://pypi.python.org/pypi/rsa/

下載下來后運(yùn)行setpy.py install安裝,然后就可以開始我們的開發(fā)步驟了。

0×02 微博登陸

搶紅包的動作一定要登陸后才可以進(jìn)行的,所以一定要有登錄的功能,登錄不是關(guān)鍵,關(guān)鍵是cookie的保存,這里需要cookielib的配合。

  1. cj = cookielib.CookieJar() 
  2. opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) 
  3. urllib2.install_opener(opener) 

這樣凡是使用opener進(jìn)行的網(wǎng)絡(luò)操作都會對處理cookie的狀態(tài),雖然我也不太懂但是感覺好神奇的樣子。

接下來需要封裝兩個模塊,一個是獲取數(shù)據(jù)模塊,用來單純地GET數(shù)據(jù),另一個用來POST數(shù)據(jù),其實只是多了幾個參數(shù),完全可以合并成一個函數(shù),但是我又懶又笨,不想也不會改代碼。

  1. def getData(url) : 
  2.         try
  3.                 req  = urllib2.Request(url) 
  4.                 result = opener.open(req) 
  5.                 text = result.read() 
  6.                 text=text.decode("utf-8").encode("gbk",'ignore'
  7.                 return text 
  8.         except Exception, e: 
  9.                 print u'請求異常,url:'+url 
  10.                 print e 
  11.    
  12. def postData(url,data,header) : 
  13.         try
  14.                 data = urllib.urlencode(data)  
  15.                 req  = urllib2.Request(url,data,header) 
  16.                 result = opener.open(req) 
  17.                 text = result.read() 
  18.                 return text 
  19.         except Exception, e: 
  20.                 print u'請求異常,url:'+url 

有了這兩個模塊我們就可以GET和POST數(shù)據(jù)了,其中g(shù)etData中之所以decode然后又encode啥啥的,是因為在Win7下我調(diào)試輸出的時候總亂碼,所以加了些編碼處理,這些都不是重點,下面的login函數(shù)才是微博登陸的核心。

  1. def login(nick , pwd) : 
  2.         print u"----------登錄中----------" 
  3.         print  "----------......----------" 
  4.         prelogin_url = 'http://login.sina.com.cn/sso/prelogin.php?entry=weibo&callback=sinaSSOController.preloginCallBack&su=%s&rsakt=mod&checkpin=1&client=ssologin.js(v1.4.15)&_=1400822309846' % nick 
  5.         preLogin = getData(prelogin_url) 
  6.         servertime = re.findall('"servertime":(.+?),' , preLogin)[0
  7.         pubkey = re.findall('"pubkey":"(.+?)",' , preLogin)[0
  8.         rsakv = re.findall('"rsakv":"(.+?)",' , preLogin)[0
  9.         nonce = re.findall('"nonce":"(.+?)",' , preLogin)[0
  10.         #print bytearray('xxxx','utf-8'
  11.         su  = base64.b64encode(urllib.quote(nick)) 
  12.         rsaPublickey= int(pubkey,16
  13.         key = rsa.PublicKey(rsaPublickey,65537
  14.         message = str(servertime) +'\t' + str(nonce) + '\n' + str(pwd) 
  15.         sp = binascii.b2a_hex(rsa.encrypt(message,key)) 
  16.         header = {'User-Agent' : 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)'
  17.         param = { 
  18.                 'entry''weibo'
  19.                 'gateway''1'
  20.                 'from'''
  21.                 'savestate''7'
  22.                 'userticket''1'
  23.                 'ssosimplelogin''1'
  24.                 'vsnf''1'
  25.                 'vsnval'''
  26.                 'su': su, 
  27.                 'service''miniblog'
  28.                 'servertime': servertime, 
  29.                 'nonce': nonce, 
  30.                 'pwencode''rsa2'
  31.                 'sp': sp, 
  32.                 'encoding''UTF-8'
  33.                 'url''http://weibo.com/ajaxlogin.php?framelogin=1&callback=parent.sinaSSOController.feedBackUrlCallBack'
  34.                 'returntype''META'
  35.                 'rsakv' : rsakv, 
  36.                 } 
  37.         s = postData('http://login.sina.com.cn/sso/login.php?client=ssologin.js(v1.4.15)',param,header) 
  38.    
  39.         try
  40.                 urll = re.findall("location.replace\(\'(.+?)\'\);" , s)[0
  41.                 login=getData(urll) 
  42.                 print u"---------登錄成功!-------" 
  43.                 print  "----------......----------" 
  44.         except Exception, e: 
  45.                 print u"---------登錄失??!-------" 
  46.                 print  "----------......----------" 
  47.                 exit(0

這里面的參數(shù)啊加密算法啊都是從網(wǎng)上抄的,我也不是很懂,大概就是先請求個時間戳和公鑰再rsa加密一下最后處理處理提交到新浪登陸接口,從新浪登錄成功之后會返回一個微博的地址,需要請求一下,才能讓登錄狀態(tài)徹底生效,登錄成功后,后面的請求就會帶上當(dāng)前用戶的cookie。

成功登錄微博后,我已迫不及待地想找個紅包先試一下子,當(dāng)然首先是要在瀏覽器里試的。點啊點啊點啊點的,終于找到了一個帶搶紅包按鈕的頁面了,F(xiàn)12召喚出調(diào)試器,看看數(shù)據(jù)包是咋請求的。

可以看到請求的地址是http://huodong.weibo.com/aj_hongbao/getlucky,主要參數(shù)有兩個,一個是ouid,就是紅包id,在URL中可以看到,另一個share參數(shù)決定是否分享到微博,還有個_t不知道是干啥用的。

好,現(xiàn)在理論上向這個url提交者三個參數(shù),就可以完成一次紅包的抽取,但是,當(dāng)你真正提交參數(shù)的時候,就會發(fā)現(xiàn)服務(wù)器會很神奇地給你返回這么個串:

  1. 1 
  2.      
  3. {"code":303403,"msg":"抱歉,你沒有權(quán)限訪問此頁面","data":[]} 

這個時候不要驚慌,根據(jù)我多年Web開發(fā)經(jīng)驗,對方的程序員應(yīng)該是判斷referer了,很簡單,把請求過去的header全給抄過去。

  1. def getLucky(id): #抽獎程序 
  2.         print u"---抽紅包中:"+str(id)+"---" 
  3.         print  "----------......----------" 
  4.    
  5.         if checkValue(id)==False: #不符合條件,這個是后面的函數(shù) 
  6.                 return 
  7.         luckyUrl="http://huodong.weibo.com/aj_hongbao/getlucky" 
  8.         param={ 
  9.                 'ouid':id, 
  10.                 'share':0
  11.                 '_t':0 
  12.                 } 
  13.    
  14.         header= { 
  15.                 'Cache-Control':'no-cache'
  16.                 'Content-Type':'application/x-www-form-urlencoded'
  17.                 'Origin':'http://huodong.weibo.com'
  18.                 'Pragma':'no-cache'
  19.                 'Referer':'http://huodong.weibo.com/hongbao/'+str(id), 
  20.                 'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 BIDUBrowser/6.x Safari/537.36'
  21.                 'X-Requested-With':'XMLHttpRequest' 
  22.                 } 
  23.         res = postData(luckyUrl,param,header) 

這樣的話理論上就沒啥問題了,事實上其實也沒啥問題。抽獎動作完成后我們是需要判斷狀態(tài)的,返回的res是一個json串,其中code為100000時為成功,為90114時是今天抽獎達(dá)到上限,其他值同樣是失敗,所以:

  1. hbRes=json.loads(res) 
  2. if hbRes["code"]=='901114': #今天紅包已經(jīng)搶完 
  3.         print u"---------已達(dá)上限---------" 
  4.         print  "----------......----------" 
  5.         log('lucky',str(id)+'---'+str(hbRes["code"])+'---'+hbRes["data"]["title"]) 
  6.         exit(0
  7. elif hbRes["code"]=='100000':#成功 
  8.         print u"---------恭喜發(fā)財---------" 
  9.         print  "----------......----------" 
  10.         log('success',str(id)+'---'+res) 
  11.         exit(0
  12.    
  13. if hbRes["data"] and hbRes["data"]["title"]: 
  14.         print hbRes["data"]["title"
  15.         print  "----------......----------" 
  16.         log('lucky',str(id)+'---'+str(hbRes["code"])+'---'+hbRes["data"]["title"]) 
  17. else
  18.         print u"---------請求錯誤---------" 
  19.         print  "----------......----------" 
  20.         log('lucky',str(id)+'---'+res) 

其中l(wèi)og也是我自定義的一個函數(shù),用來記錄日志用的:

  1. def log(type,text): 
  2.         fp = open(type+'.txt','a'
  3.         fp.write(text) 
  4.         fp.write('\r\n'
  5.         fp.close() 

0×04 爬取紅包列表

單個紅包領(lǐng)取動作測試成功后,就是我們程序的核心大招模塊了——爬取紅包列表,爬取紅包列表的方法和入口應(yīng)該有不少,比如各種微博搜索關(guān)鍵字啥啥的,不過我這里用最簡單的方法:爬取紅包榜單。

在紅包活動的首頁(http://huodong.weibo.com/hongbao)通過各種點更多,全部可以觀察到,雖然列表連接很多,但可以歸納為兩類(最有錢紅包榜除外):主題和排行榜。

繼續(xù)召喚F12,分析這兩種頁面的格式,首先是主題形式的列表,比如:http://huodong.weibo.com/hongbao/special_quyu

可以看到紅包的信息都是在一個類名為info_wrap的div中,那么我們只要活動這個頁面的源碼,然后把infowrap全抓出來,再簡單處理下就可以得到這個頁面的紅包列表了,這里需要用到一些正則:

  1. def getThemeList(url,p):#主題紅包 
  2.         print  u"---------第"+str(p)+"頁---------" 
  3.         print  "----------......----------" 
  4.         html=getData(url+'?p='+str(p)) 
  5.         pWrap=re.compile(r'(.+?)',re.DOTALL) #h獲取所有info_wrap的正則 
  6.         pInfo=re.compile(r'.+(.+).+(.+).+(.+).+href="(.+)" class="btn"',re.DOTALL) #獲取紅包信息 
  7.         List=pWrap.findall(html,re.DOTALL) 
  8.         n=len(List) 
  9.         if n==0
  10.                 return 
  11.         for i in range(n): #遍歷所有info_wrap的div 
  12.                 s=pInfo.match(List[i]) #取得紅包信息 
  13.                 info=list(s.groups(0)) 
  14.                 info[0]=float(info[0].replace('\xcd\xf2','0000')) #現(xiàn)金,萬->0000 
  15.                 try
  16.                         info[1]=float(info[1].replace('\xcd\xf2','0000')) #禮品價值 
  17.                 except Exception, e: 
  18.                         info[1]=float(info[1].replace('\xd2\xda','00000000')) #禮品價值 
  19.                 info[2]=float(info[2].replace('\xcd\xf2','0000')) #已發(fā)送 
  20.                 if info[2]==0
  21.                         info[2]=1 #防止除數(shù)為0 
  22.                 if info[1]==0
  23.                         info[1]=1 #防止除數(shù)為0 
  24.                 info.append(info[0]/(info[2]+info[1])) #紅包價值,現(xiàn)金/(領(lǐng)取人數(shù)+獎品價值) 
  25.                 # if info[0]/(info[2]+info[1])>100
  26.                 #  print url 
  27.                 luckyList.append(info) 
  28.         if 'class="page"' in html:#存在下一頁 
  29.                 p=p+1 
  30.                 getThemeList(url,p) #遞歸調(diào)用自己爬取下一頁 

話說正則好難,學(xué)了好久才寫出來這么兩句。還有這里的info中append進(jìn)去了一個info[4],是我想的一個大概判斷紅包價值的算法,為什么要這么做呢,因為紅包很多但是我們只能抽四次啊,在茫茫包海中,我們必須要找到最有價值的紅包然后抽丫的,這里有三個數(shù)據(jù)可供參考:現(xiàn)金價值、禮品價值和領(lǐng)取人數(shù),很顯然如果現(xiàn)金很少領(lǐng)取人數(shù)很多或者獎品價值超高(有的甚至喪心病狂以億為單位),那么就是不值得去搶的,所以我憋了半天終于憋出來一個衡量紅包權(quán)重的算法:紅包價值=現(xiàn)金/(領(lǐng)取人數(shù)+獎品價值)。

排行榜頁面原理一樣,找到關(guān)鍵的標(biāo)簽,正則匹配出來。

 

  1. def getTopList(url,daily,p):#排行榜紅包 
  2.         print  u"---------第"+str(p)+"頁---------" 
  3.         print  "----------......----------" 
  4.         html=getData(url+'?daily='+str(daily)+'&p='+str(p)) 
  5.         pWrap=re.compile(r'(.+?)',re.DOTALL) #h獲取所有l(wèi)ist_info的正則 
  6.         pInfo=re.compile(r'.+(.+).+(.+).+(.+).+href="(.+)" class="btn rob_btn"',re.DOTALL) #獲取紅包信息 
  7.         List=pWrap.findall(html,re.DOTALL) 
  8.         n=len(List) 
  9.         if n==0
  10.                 return 
  11.         for i in range(n): #遍歷所有info_wrap的div 
  12.                 s=pInfo.match(List[i]) #取得紅包信息 
  13.                 topinfo=list(s.groups(0)) 
  14.                 info=list(topinfo) 
  15.                 info[0]=topinfo[1].replace('\xd4\xaa','') #元->'' 
  16.                 info[0]=float(info[0].replace('\xcd\xf2','0000')) #現(xiàn)金,萬->0000 
  17.                 info[1]=topinfo[2].replace('\xd4\xaa','') #元->'' 
  18.                 try
  19.                         info[1]=float(info[1].replace('\xcd\xf2','0000')) #禮品價值 
  20.                 except Exception, e: 
  21.                         info[1]=float(info[1].replace('\xd2\xda','00000000')) #禮品價值 
  22.                 info[2]=topinfo[0].replace('\xb8\xf6','') #個->'' 
  23.                 info[2]=float(info[2].replace('\xcd\xf2','0000')) #已發(fā)送 
  24.                 if info[2]==0
  25.                         info[2]=1 #防止除數(shù)為0 
  26.                 if info[1]==0
  27.                         info[1]=1 #防止除數(shù)為0 
  28.                 info.append(info[0]/(info[2]+info[1])) #紅包價值,現(xiàn)金/(領(lǐng)取人數(shù)+禮品價值) 
  29.                 # if info[0]/(info[2]+info[1])>100
  30.                         #  print url 
  31.                 luckyList.append(info) 
  32.         if 'class="page"' in html:#存在下一頁 
  33.                 p=p+1 
  34.                 getTopList(url,daily,p) #遞歸調(diào)用自己爬取下一頁 

好,現(xiàn)在兩中專題頁的列表我們都可以順利爬取了,接下來就是要得到列表的列表,也就是所有這些列表地址的集合,然后挨個去抓:

  1. def getList(): 
  2.         print u"---------查找目標(biāo)---------" 
  3.         print  "----------......----------" 
  4.    
  5.         themeUrl={ #主題列表 
  6.                 'theme':'http://huodong.weibo.com/hongbao/theme'
  7.                 'pinpai':'http://huodong.weibo.com/hongbao/special_pinpai'
  8.                 'daka':'http://huodong.weibo.com/hongbao/special_daka'
  9.                 'youxuan':'http://huodong.weibo.com/hongbao/special_youxuan'
  10.                 'qiye':'http://huodong.weibo.com/hongbao/special_qiye'
  11.                 'quyu':'http://huodong.weibo.com/hongbao/special_quyu'
  12.                 'meiti':'http://huodong.weibo.com/hongbao/special_meiti'
  13.                 'hezuo':'http://huodong.weibo.com/hongbao/special_hezuo' 
  14.                 } 
  15.    
  16.         topUrl={ #排行榜列表 
  17.                 'mostmoney':'http://huodong.weibo.com/hongbao/top_mostmoney'
  18.                 'mostsend':'http://huodong.weibo.com/hongbao/top_mostsend'
  19.                 'mostsenddaka':'http://huodong.weibo.com/hongbao/top_mostsenddaka'
  20.                 'mostsendpartner':'http://huodong.weibo.com/hongbao/top_mostsendpartner'
  21.                 'cate':'http://huodong.weibo.com/hongbao/cate?type='
  22.                 'clothes':'http://huodong.weibo.com/hongbao/cate?type=clothes'
  23.                 'beauty':'http://huodong.weibo.com/hongbao/cate?type=beauty'
  24.                 'fast':'http://huodong.weibo.com/hongbao/cate?type=fast'
  25.                 'life':'http://huodong.weibo.com/hongbao/cate?type=life'
  26.                 'digital':'http://huodong.weibo.com/hongbao/cate?type=digital'
  27.                 'other':'http://huodong.weibo.com/hongbao/cate?type=other' 
  28.                 } 
  29.    
  30.         for (theme,url) in themeUrl.items(): 
  31.                 print "----------"+theme+"----------" 
  32.                 print  url 
  33.                 print  "----------......----------" 
  34.                 getThemeList(url,1
  35.    
  36.         for (top,url) in topUrl.items(): 
  37.                 print "----------"+top+"----------" 
  38.                 print  url 
  39.                 print  "----------......----------" 
  40.                 getTopList(url,0,1)  
  41.                 getTopList(url,1,1

0×05 判斷紅包可用性

這個是比較簡單的,首先在源碼里搜一下關(guān)鍵字看看有沒有搶紅包按鈕,然后再到領(lǐng)取排行里面看看最高紀(jì)錄是多少,要是最多的才領(lǐng)那么幾塊錢的話就再見吧……

其中查看領(lǐng)取記錄的地址為http://huodong.weibo.com/aj_hongbao/detailmore?page=1&type=2&_t=0&__rnd=1423744829265&uid=紅包id

  1. def checkValue(id): 
  2.         infoUrl='http://huodong.weibo.com/hongbao/'+str(id) 
  3.         html=getData(infoUrl) 
  4.    
  5.         if 'action-type="lottery"' in  html or True: #存在搶紅包按鈕 
  6.                 logUrl="http://huodong.weibo.com/aj_hongbao/detailmore?page=1&type=2&_t=0&__rnd=1423744829265&uid="+id #查看排行榜數(shù)據(jù) 
  7.                 param={} 
  8.                 header= { 
  9.                         'Cache-Control':'no-cache'
  10.                         'Content-Type':'application/x-www-form-urlencoded'
  11.                         'Pragma':'no-cache'
  12.                         'Referer':'http://huodong.weibo.com/hongbao/detail?uid='+str(id), 
  13.                         'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 BIDUBrowser/6.x Safari/537.36'
  14.                         'X-Requested-With':'XMLHttpRequest' 
  15.                         } 
  16.                 res = postData(logUrl,param,header) 
  17.                 pMoney=re.compile(r'< span class="money">(\d+?.+?)\xd4\xaa< /span>',re.DOTALL) #h獲取所有l(wèi)ist_info的正則 
  18.                 luckyLog=pMoney.findall(html,re.DOTALL) 
  19.    
  20.                 if len(luckyLog)==0
  21.                         maxMoney=0 
  22.                 else
  23.                         maxMoney=float(luckyLog[0]) 
  24.    
  25.                 if maxMoney< lowest: #記錄中最大紅包小于設(shè)定值 
  26.                         return False 
  27.         else
  28.                 print u"---------手慢一步---------" 
  29.                 print  "----------......----------" 
  30.                 return False 
  31.         return True 

0×06 收尾工作

主要的模塊都已經(jīng)搞定,現(xiàn)在需要將所有的步驟串聯(lián)起來:

  1. def start(username,password,low,fromFile): 
  2.         gl=False 
  3.         lowest=low 
  4.         login(username , password) 
  5.         if fromfile=='y'
  6.                 if os.path.exists('luckyList.txt'): 
  7.                         try
  8.                                 f = file('luckyList.txt'
  9.                                 newList = []   
  10.                                 newList = p.load(f) 
  11.                                 print u'---------裝載列表---------' 
  12.                                 print  "----------......----------" 
  13.                         except Exception, e: 
  14.                                 print u'解析本地列表失敗,抓取在線頁面。' 
  15.                                 print  "----------......----------" 
  16.                                 gl=True 
  17.                 else
  18.                         print u'本地不存在luckyList.txt,抓取在線頁面。' 
  19.                         print  "----------......----------" 
  20.                         gl=True 
  21.         if gl==True: 
  22.                 getList() 
  23.                 from operator import itemgetter 
  24.                 newList=sorted(luckyList, key=itemgetter(4),reverse=True) 
  25.                 f = file('luckyList.txt''w')   
  26.                 p.dump(newList, f) #把抓到的列表存到文件里,下次就不用再抓了 
  27.                 f.close()  
  28.    
  29.         for lucky in newList: 
  30.                 if not 'http://huodong.weibo.com' in lucky[3]: #不是紅包 
  31.                         continue 
  32.                 print lucky[3
  33.                 id=re.findall(r'(\w*[0-9]+)\w*',lucky[3]) 
  34.                 getLucky(id[0]) 

因為每次測試的時候都要重復(fù)爬取紅包列表,很麻煩,所以加了段將完整列表dump到文件的代碼,這樣以后就可以讀本地列表然后搶紅包了,構(gòu)造完start模塊后,寫一個入口程序把微博賬號傳過去就OK了:

  1. if __name__ == "__main__":   
  2.         print u"------------------微博紅包助手------------------" 
  3.         print  "---------------------v0.0.1---------------------" 
  4.         print  u"-------------by @無所不能的魂大人----------------" 
  5.         print  "-------------------------------------------------" 
  6.    
  7.         try
  8.                 uname=raw_input(u"請輸入微博賬號: ".decode('utf-8').encode('gbk')) 
  9.                 pwd=raw_input(u"請輸入微博密碼: ".decode('utf-8').encode('gbk')) 
  10.                 low=int(raw_input(u"紅包領(lǐng)取最高現(xiàn)金大于n時參與: ".decode('utf-8').encode('gbk'))) 
  11.                 fromfile=raw_input(u"是否使用luckyList.txt中紅包列表:(y/n) ".decode('utf-8').encode('gbk')) 
  12.         except Exception, e: 
  13.                 print u"參數(shù)錯誤" 
  14.                 print  "----------......----------" 
  15.                 print e 
  16.                 exit(0
  17.    
  18.         print u"---------程序開始---------" 
  19.         print  "----------......----------" 
  20.         start(uname,pwd,low,fromfile) 
  21.         print u"---------程序結(jié)束---------" 
  22.         print  "----------......----------" 
  23.         os.system('pause'

0×07 走你!

基本的爬蟲骨架已經(jīng)基本可以完成了,其實這個爬蟲的很多細(xì)節(jié)上還是有很大發(fā)揮空間的,比如改裝成支持批量登錄的,比如優(yōu)化下紅包價值算法,代碼本身應(yīng)該也有很多地方可以優(yōu)化的,不過以我的能力估計也就能搞到這了。

最后程序的結(jié)果大家都看到了,我寫了幾百行代碼,幾千字的文章,辛辛苦苦換來的只是一組雙色球,尼瑪坑爹啊,怎么會是雙色球呢!?。。ㄅ园祝鹤髡咴秸f越激動,居然哭了起來,周圍人紛紛勸說:兄弟,不至于的,不就是個微博紅包么,昨天手都擼酸了也沒搖出個微信紅包。)

唉,其實我不是哭這個,我難過的是我已經(jīng)二十多歲了,還在做寫程序抓微博紅包這么無聊的事情,這根本不是我想要的人生啊!

源碼下載:http://down.51cto.com/data/1984536

責(zé)任編輯:林師授 來源: freebuf
相關(guān)推薦

2024-08-19 11:31:41

2015-02-27 15:19:36

微信紅包算法

2017-01-20 11:14:37

紅包

2019-08-29 09:57:24

Python系統(tǒng)編程

2015-02-27 09:45:25

搶紅包手機(jī)

2016-12-27 09:49:59

支付寶紅包破解

2016-03-02 14:01:53

2021-11-16 23:11:24

Java微信搶紅包

2015-02-26 13:34:28

2015-02-28 21:10:35

4G斐訊C530搶紅包

2015-12-31 11:30:10

趨勢科技/信息安全

2018-11-12 10:20:29

網(wǎng)絡(luò)安全網(wǎng)絡(luò)安全技術(shù)周刊

2014-04-18 17:43:52

電商 騰訊 應(yīng)用寶 smb.chinaby132

2020-09-01 07:47:32

Redis秒殺微信

2015-02-26 13:43:18

微信支付寶紅包

2016-12-28 16:30:50

51CTO 福利

2021-07-18 11:52:07

微信紅包移動應(yīng)用

2014-02-13 09:40:20

架構(gòu)師春節(jié)旅游

2015-11-05 10:24:37

數(shù)據(jù)中心微信
點贊
收藏

51CTO技術(shù)棧公眾號