python實(shí)現(xiàn)淘寶秒殺聚劃算搶購(gòu)自動(dòng)提醒源碼
說(shuō)明
本實(shí)例能夠監(jiān)控聚劃算的搶購(gòu)按鈕,在聚劃算整點(diǎn)聚的時(shí)間到達(dá)時(shí)發(fā)出提醒(音頻文件自己定義位置)并自動(dòng)彈開(kāi)頁(yè)面(URL自己定義)。
同時(shí)還可以通過(guò)命令行參數(shù)自定義刷新間隔時(shí)間(默認(rèn)0.1s)和監(jiān)控持續(xù)時(shí)間(默認(rèn)1800s)。
源碼
# encoding: utf-8
'''''
@author: Techzero
@email: techzero@163.com
@time: 2014-5-18 下午5:06:29
'''
import cStringIO
import getopt
import time
import urllib2
import subprocess
import sys
from datetime import datetime
MEDIA_PLAYER = 'C:/Program Files/Windows Media Player/wmplayer.exe'
MEDIA_FILE = 'D:/notify.mp3'
CHROME = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe'
URL = 'http://detail.ju.taobao.com/home.htm?spm=608.2214381.2.1.SY0wVT&item_id=16761325430&id=10000002801432'
NO_X11 = False
def get_current_button():
'''''獲取當(dāng)前按鈕狀態(tài)'''
content = urllib2.urlopen(URL).read() #獲取頁(yè)面內(nèi)容
buf = cStringIO.StringIO(content.decode('gbk').encode('utf8')) #將頁(yè)面內(nèi)容轉(zhuǎn)換為輸入流
current_button = None
for line in buf:
line = line.strip(' \n\r') #去掉回車(chē)換行
if line.find(r'<a href="#" rel="external nofollow" class="extra notice J_BuyButtonSub">開(kāi)團(tuán)提醒</a>') != -1:
current_button = '開(kāi)團(tuán)提醒'
break
elif line.find(r'<div class="main-box chance ">') != -1:
current_button = '還有機(jī)會(huì)'
break
elif line.find(r'<span class="out floatright">賣(mài)光了...</span>') != -1:
current_button = '賣(mài)光了'
break
elif line.find(r'<span class="out floatright">已結(jié)束...</span>') != -1:
current_button = '已結(jié)束'
break
elif line.find(r'<input type="submit" class="buyaction J_BuySubmit" title="馬上搶" value="馬上搶"/>') != -1:
current_button = '馬上搶'
break
buf.close()
return current_button
def notify():
'''''發(fā)出通知并用Chrome打開(kāi)秒殺頁(yè)面'''
subprocess.Popen([MEDIA_PLAYER, MEDIA_FILE])
if not NO_X11:
subprocess.Popen([CHROME, URL])
print '打開(kāi)頁(yè)面'
def monitor_button(interval, last):
'''''開(kāi)始監(jiān)視按鈕'''
elapse = 0
while elapse < last:
current_button = get_current_button()
now = datetime.now()
print '%d-%d-%d %d:%d:%d - 現(xiàn)在按鈕是 %s' % (now.year, now.month, now.day, now.hour, now.minute, now.second, current_button)
if current_button == '馬上搶' or current_button == '還有機(jī)會(huì)':
print '趕緊搶購(gòu)!'
notify()
break
elif current_button == '賣(mài)光了' or current_button == '已結(jié)束':
print '下次再試吧!'
break
else:
print '還沒(méi)開(kāi)始呢,再等等吧!'
time.sleep(interval)
elapse += interval
def usage():
print '''''
usage: monitor_mac_price.py [options]
Options:
-i interval: 30 seconds by default.
-l last: 1800 seconds by default.
-h: Print this usage.
-X: Run under no X11.
'''
if __name__ == '__main__':
try:
opts, args = getopt.getopt(sys.argv[1:], 'i:l:hX')
except getopt.GetoptError, err:
print str(err)
sys.exit(1)
interval = 0.1
last = 1800
for opt, val in opts:
if opt == '-i':
interval = int(val)
elif opt == '-l':
last = int(val)
elif opt == '-X':
NO_X11 = True
elif opt == '-h':
usage()
sys.exit()
monitor_button(interval, last)
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
python 爬取華為應(yīng)用市場(chǎng)評(píng)論
項(xiàng)目需要爬取評(píng)論數(shù)據(jù),在此做一個(gè)記錄,這里爬取的是web端的數(shù)據(jù),以后可能會(huì)考慮爬取android app中的數(shù)據(jù)。2021-05-05
Python多線(xiàn)程編程(八):使用Event實(shí)現(xiàn)線(xiàn)程間通信
這篇文章主要介紹了Python多線(xiàn)程編程(八):使用Event實(shí)現(xiàn)線(xiàn)程間通信,,需要的朋友可以參考下2015-04-04
python實(shí)現(xiàn)字典合并的五種方法(附示例代碼)
在Python中,有多種方法可以通過(guò)使用各種函數(shù)和構(gòu)造函數(shù)來(lái)合并字典,在本文中,我們將討論一些合并字典的方法,并通過(guò)代碼示例講解的非常詳細(xì),具有一定的參考價(jià)值,需要的朋友可以參考下2024-04-04
19個(gè)Python?Sklearn中超實(shí)用的隱藏功能分享
今天跟大家介紹?19?個(gè)?Sklearn?中超級(jí)實(shí)用的隱藏的功能,這些功能雖然不常見(jiàn),但非常實(shí)用,它們可以直接優(yōu)雅地替代手動(dòng)執(zhí)行的常見(jiàn)操作2022-07-07
Python開(kāi)發(fā)之基于模板匹配的信用卡數(shù)字識(shí)別功能
這篇文章主要介紹了基于模板匹配的信用卡數(shù)字識(shí)別功能,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-01-01

