python实现淘宝秒杀聚划算抢购自动提醒源码


Posted in Python onJune 23, 2020

说明

本实例能够监控聚划算的抢购按钮,在聚划算整点聚的时间到达时发出提醒(音频文件自己定义位置)并自动弹开页面(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)

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Python 相关文章推荐
跟老齐学Python之折腾一下目录
Oct 24 Python
Python中用Spark模块的使用教程
Apr 13 Python
Python的Django框架中settings文件的部署建议
May 30 Python
Python的自动化部署模块Fabric的安装及使用指南
Jan 19 Python
Python语言实现获取主机名根据端口杀死进程
Mar 31 Python
python中requests小技巧
May 10 Python
Python Pillow Image Invert
Jan 22 Python
Django-Model数据库操作(增删改查、连表结构)详解
Jul 17 Python
Django CBV与FBV原理及实例详解
Aug 12 Python
原生python实现knn分类算法
Oct 24 Python
python源文件的字符编码知识点详解
Mar 04 Python
Python实现猜拳与猜数字游戏的方法详解
Apr 06 Python
初探TensorFLow从文件读取图片的四种方式
Feb 06 #Python
用十张图详解TensorFlow数据读取机制(附代码)
Feb 06 #Python
Python实现matplotlib显示中文的方法详解
Feb 06 #Python
Python实现自动上京东抢手机
Feb 06 #Python
Python获取指定文件夹下的文件名的方法
Feb 06 #Python
TensorFlow如何实现反向传播
Feb 06 #Python
tensorflow TFRecords文件的生成和读取的方法
Feb 06 #Python
You might like
PHP入门速成(2)
2006/10/09 PHP
人尽可用的Windows技巧小贴士之下篇
2007/03/22 PHP
PHP中基本符号及使用方法
2010/03/23 PHP
PHP合并两个数组的两种方式的异同
2012/09/14 PHP
PHP针对JSON操作实例分析
2015/01/12 PHP
PHP+jQuery翻板抽奖功能实现
2015/10/19 PHP
Apache无法自动跳转却显示目录的解决方法
2020/11/30 PHP
php mysql操作mysql_connect连接数据库实例详解
2016/12/26 PHP
基于jquery的Repeater实现代码
2010/07/17 Javascript
js中AppendChild与insertBefore的用法详细解析
2013/12/16 Javascript
nodejs实现黑名单中间件设计
2014/06/17 NodeJs
js计算文本框输入的字符数
2015/10/23 Javascript
详解webpack+es6+angular1.x项目构建
2017/05/02 Javascript
JavaScript实现form表单的多文件上传
2020/03/27 Javascript
JavaScript动态绑定详解
2017/09/14 Javascript
详解VSCode配置启动Vue项目
2019/05/14 Javascript
vue通信方式EventBus的实现代码详解
2019/06/10 Javascript
java实现单链表增删改查的实例代码详解
2019/08/30 Javascript
在antd Table中插入可编辑的单元格实例
2020/10/28 Javascript
用Python脚本生成Android SALT扰码的方法
2013/09/18 Python
用python代码做configure文件
2014/07/20 Python
python re模块findall()函数实例解析
2018/01/19 Python
python利用多种方式来统计词频(单词个数)
2019/05/27 Python
解决Python pip 自动更新升级失败的问题
2020/02/21 Python
详解python使用金山词霸的翻译功能(调试工具断点的使用)
2021/01/07 Python
家庭户外服装:Hawkshead
2017/11/02 全球购物
LN-CC英国:伦敦时尚生活的缩影
2019/09/01 全球购物
COSETTE官网:奢华,每天
2020/03/22 全球购物
网上书店创业计划书
2014/01/12 职场文书
基层干部十八大感言
2014/01/19 职场文书
校园运动会广播稿
2015/08/19 职场文书
环保建议书作文500字
2015/09/14 职场文书
2019年感恩励志演讲稿(收藏备用)
2019/09/11 职场文书
六年级情感作文之500字
2019/10/23 职场文书
windows安装 redis 6.2.6最新步骤详解
2022/04/26 Redis
Promise静态四兄弟实现示例详解
2022/07/07 Javascript