国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python實現淘寶秒殺聚劃算搶購自動提醒源碼

2020-02-22 23:08:36
字體:
來源:轉載
供稿:網友

說明

本實例能夠監控聚劃算的搶購按鈕,在聚劃算整點聚的時間到達時發出提醒(音頻文件自己定義位置)并自動彈開頁面(URL自己定義)。

同時還可以通過命令行參數自定義刷新間隔時間(默認0.1s)和監控持續時間(默認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():   '''''獲取當前按鈕狀態'''   content = urllib2.urlopen(URL).read() #獲取頁面內容      buf = cStringIO.StringIO(content.decode('gbk').encode('utf8')) #將頁面內容轉換為輸入流   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">開團提醒</a>') != -1:       current_button = '開團提醒'       break     elif line.find(r'<div class="main-box chance ">') != -1:       current_button = '還有機會'       break     elif line.find(r'<span class="out floatright">賣光了...</span>') != -1:       current_button = '賣光了'       break     elif line.find(r'<span class="out floatright">已結束...</span>') != -1:       current_button = '已結束'       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():   '''''發出通知并用Chrome打開秒殺頁面'''   subprocess.Popen([MEDIA_PLAYER, MEDIA_FILE])   if not NO_X11:     subprocess.Popen([CHROME, URL])     print '打開頁面'   def monitor_button(interval, last):   '''''開始監視按鈕'''   elapse = 0   while elapse < last:     current_button = get_current_button()      now = datetime.now()     print '%d-%d-%d %d:%d:%d - 現在按鈕是 %s' % (now.year, now.month, now.day, now.hour, now.minute, now.second, current_button)      if current_button == '馬上搶' or current_button == '還有機會':       print '趕緊搶購!'       notify()       break     elif current_button == '賣光了' or current_button == '已結束':       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)             
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 永兴县| 广宗县| 临高县| 二连浩特市| 年辖:市辖区| 油尖旺区| 湖州市| 陆河县| 芦山县| 南漳县| 靖江市| 庆云县| 丰宁| 馆陶县| 天祝| 特克斯县| 青铜峡市| 徐水县| 镇巴县| 汪清县| 马关县| 永顺县| 湖北省| 平陆县| 罗山县| 城口县| 大埔区| 裕民县| 桃园市| 祁连县| 白水县| 浑源县| 策勒县| 华池县| 祥云县| 漳州市| 贺州市| 新密市| 凤冈县| 清水县| 育儿|