python實(shí)現(xiàn)淘寶秒殺聚劃算搶購自動(dòng)提醒源碼
說明
本實(shí)例能夠監(jiān)控聚劃算的搶購按鈕,在聚劃算整點(diǎn)聚的時(shí)間到達(dá)時(shí)發(fā)出提醒(音頻文件自己定義位置)并自動(dòng)彈開頁面(URL自己定義)。
同時(shí)還可以通過命令行參數(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() #獲取頁面內(nèi)容
buf = cStringIO.StringIO(content.decode('gbk').encode('utf8')) #將頁面內(nèi)容轉(zhuǎn)換為輸入流
current_button = None
for line in buf:
line = line.strip(' \n\r') #去掉回車換行
if line.find(r'<a href="#" rel="external nofollow" class="extra notice J_BuyButtonSub">開團(tuán)提醒</a>') != -1:
current_button = '開團(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">賣光了...</span>') != -1:
current_button = '賣光了'
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打開秒殺頁面'''
subprocess.Popen([MEDIA_PLAYER, MEDIA_FILE])
if not NO_X11:
subprocess.Popen([CHROME, URL])
print '打開頁面'
def monitor_button(interval, last):
'''''開始監(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 '趕緊搶購!'
notify()
break
elif current_button == '賣光了' or current_button == '已結(jié)束':
print '下次再試吧!'
break
else:
print '還沒開始呢,再等等吧!'
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)
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Python實(shí)現(xiàn)字符串模糊匹配的兩種實(shí)現(xiàn)方法
本文主要介紹了Python實(shí)現(xiàn)字符串模糊匹配的兩種實(shí)現(xiàn)方法,Python中通過re.search()方法實(shí)現(xiàn),對于首位起始的內(nèi)容匹配,也可通過re.match()方法實(shí)現(xiàn),感興趣的可以了解一下2023-11-11
python實(shí)現(xiàn)對象列表根據(jù)某個(gè)屬性排序的方法詳解
這篇文章主要介紹了python實(shí)現(xiàn)對象列表根據(jù)某個(gè)屬性排序的方法,結(jié)合具體實(shí)例形式詳細(xì)分析了Python對象列表遍歷、排序的兩種常見操作技巧,需要的朋友可以參考下2019-06-06
python實(shí)現(xiàn)可下載音樂的音樂播放器
這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)可下載音樂的音樂播放器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-02-02
python可視化篇之流式數(shù)據(jù)監(jiān)控的實(shí)現(xiàn)
這篇文章主要介紹了python可視化篇之流式數(shù)據(jù)監(jiān)控的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08
Python如何操作office實(shí)現(xiàn)自動(dòng)化及win32com.client的運(yùn)用
這篇文章主要介紹了Python如何操作office實(shí)現(xiàn)自動(dòng)化及win32com.client的運(yùn)用,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-04-04

