分類
程序

python3字符串自增

週末喝恆大冰泉,發現掃二維碼中獎概率頗高,而且可以中獎金額直接用來給手機充值或提現到銀行卡,做的比較好。趁理髮無聊的時候寫了段python掃了一會兒,但是空手而歸。代碼也很簡單和用Python抓取大衆點評的用戶評論差不多,主要就是字符串自增這塊用了個遞歸:

from bs4 import BeautifulSoup import string,sys,time,random,urllib,http.cookiejar,socket #url="https://sao.so/t/dSTUVvjUhPHpz" baseDir="/storage/sdcard0/com.hipipal.qpyplus/scripts3/test/" base="_0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" HDcode="dSTUVvjUhPIjL" bingoNo=0 failNo=0 def increase(s): sHead=s[0:-1] sFoot=s[-1:] sNew="" if(sFoot != "Z"): index=base.index(sFoot) sFootNew=base[index+1] sNew=sHead+sFootNew else: sHeadNew=increase(sHead) sFootNew="_" sNew=sHeadNew+sFootNew return sNew def getHTML(url): request = urllib.request.Request(url) request.add_header("User-Agent", "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:37.0) Gecko/20100101 Firefox/37.0") try: response = urllib.request.urlopen(request) except (urllib.error.HTTPError, socket.error,urllib.error.URLError) as e: print('Connection error occurred when inserting data.'+str(e)) else: if response.code != 200: print("Error code:"+response.code) else: html = response.read().decode('utf-8') return html def check(html): global bingoNo global failNo #with open(baseDir+'expired.html',encoding='utf-8') as html: soup = BeautifulSoup(html) images = soup.find_all('img') for image in images: if "errorQrCode.jpg" in image.get('src') : failNo = failNo + 1 print("fake: " + HDcode + " " + str(failNo)) break elif "冰泉君已经失身啦" in soup.get_text(): print("expired" + HDcode) break else: print("bingo" + HDcode) bingoNo = bingoNo + 4 if __name__ == '__main__': #html=getHTML(url) #with open(baseDir+'fake.html', mode='w', encoding='utf-8') as html_file: #html_file.write(html) global HDcode while(bingoNo < 2): url = "https://sao.so/t/" + HDcode html = getHTML(url) check(html) HDcode = increase(HDcode) time.sleep(random.randrange(4,7)) [/code]

其實命中的概率真的非常低,拿13位編碼來說,一共有(11+26+26)^13=2.46*10^23種組合,瓶子上說中獎概率33.3%,按300億銷售目標和5元均價算,一共有2×10^10瓶是可以中獎的。除一下就發現……不用除了吧

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *